小编use*_*492的帖子

在Map中添加两次相同的键

我正在研究Maps,我发现如果我故意两次添加相同的密钥,那么Map的大小保持不变.这背后的技术原因是什么?

 Map map=new HashMap();//HashMap key random order.
         map.put("Amit","Java");
         map.put("Amit","Java");
Run Code Online (Sandbox Code Playgroud)

检索代码......

System.out.println("There are "+map.size()+" elements in the map.");
         System.out.println("Content of Map are...");
         Set s=map.entrySet();
         Iterator itr=s.iterator();
         while(itr.hasNext())
         {
             Map.Entry m=(Map.Entry)itr.next();
             System.out.println(m.getKey()+"\t"+m.getValue()+"\t"+ m.hashCode());
          }
Run Code Online (Sandbox Code Playgroud)

结果我得到:

There are 1 elements in the map.
Content of Map are...
Amit    Java    3943477
Run Code Online (Sandbox Code Playgroud)

java collections hashmap

8
推荐指数
1
解决办法
2万
查看次数

地图和列表中的ModCount

在eclispse中调试集合时我只是检查有一个名为modCount的东西,例如,如果我们调试列表,我们将在调试时看到这个modCount表示的内容.!!请指教

java collections list hashmap

4
推荐指数
1
解决办法
4137
查看次数

关于junit测试用例

我是Junit测试用例世界的新手,我只是想知道如果我开发了一个程序

class MapDemo1
{static final Logger logger = Logger.getLogger(MapDemo1.class);
     /**
     *  
     */
    public static void main(String arg[])
     {PropertyConfigurator.configure("src/log4j.properties");
     logger.info("-->Map");
    // Map map=new TreeMap();

         Map map=new HashMap();//HashMap key random order.
      //   System.out.println("Amit".hashCode());
         map.put("Amit","Java");
         map.put("Amit","Javas");
        // map.put("mAit","J2EE");
         //map.put("Saral","J2rrrEE");
         /*map.put("ty","Spring");
         map.put("Anupam","Hibernate");
         map.put("Ravi",".Net");
         map.put("Saral","Andriod");//same key but different value 
         map.put("Nitin","PHP");
         map.put("hj","Spring1");*/
         System.out.println("There are "+map.size()+" elements in the map.");
         System.out.println("Content of Map are...");
         Set s=map.entrySet();
         Iterator itr=s.iterator();
         while(itr.hasNext())
         {
             Map.Entry m=(Map.Entry)itr.next();
             System.out.println(m.getKey()+"\t"+m.getValue()+"\t"+ m.hashCode());
          }
]
}
Run Code Online (Sandbox Code Playgroud)

现在请告知这个junit测试用例是什么以及如何在seprate类中编写.

java junit junit4

-1
推荐指数
1
解决办法
625
查看次数

关于检索列表时出错

可能重复:
关于并发修改异常

我在下面的代码中得到这个并发修改异常错误,因为我试图在迭代时删除元素..代码在下面..

 List  list=new ArrayList ();
          list.add(new Emp("Saral","Trainer",34500));
          list.add(new Emp("Saral","Trainer",36000));
          list.add(new Emp("Saral","Trainer",33000));
          list.add(new Emp("Sachin","Programmer",24000));
Run Code Online (Sandbox Code Playgroud)

而我正在检索的方式是..

System.out.println("Content of list are : ");
          ListIterator itr1=list.listIterator();
          while(itr1.hasNext())
          {
              list.add(new Emp("Anand","Manager",56000)); //
            Emp e=(Emp)itr1.next();  
            e.display();
          }
Run Code Online (Sandbox Code Playgroud)

你能告诉我这个错误是如何避免的吗?

java

-2
推荐指数
1
解决办法
50
查看次数

标签 统计

java ×4

collections ×2

hashmap ×2

junit ×1

junit4 ×1

list ×1