Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1069612
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类:

2009-12-08 14:29:29

package com;

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

class Temp
{
    public int count;
    
    public Temp()
    {
        this.count = 123;
    }
    
    public void setCount(int count)
    {
        this.count = count;
    }
    
    public int getCount()
    {
        return this.count;
    }
}

public class Test
{
    public static void main(String args[]) throws Exception
    {
        HashMap<String, Temp> hashmap = new HashMap<String, Temp>();

        Temp t = new Temp();
        
        hashmap.put("fan", t);
        
        Set<Map.Entry<String, Temp>> set = hashmap.entrySet();
        Iterator<Map.Entry<String, Temp>> iterator = set.iterator();
        while (iterator.hasNext())
        {
            Entry<String, Temp> entry = iterator.next();
            String key = entry.getKey();
            Temp tt = entry.getValue();
            
            System.out.println("key: " + key + " value = " + tt.getCount());
        }
        
        hashmap.clear();
    }
}


阅读(937) | 评论(0) | 转发(0) |
0

上一篇:hashmap遍历

下一篇:gettimeofday/settimeofday

给主人留下些什么吧!~~