关于Iterator遍历取值顺序的问题
Map<Integer,String>map=newHashMap<Integer,String>();map.put(1213,"A");map.put(2324,"B...
Map<Integer, String> map=new HashMap<Integer, String>();
map.put(1213, "A");
map.put(2324, "B");
map.put(35436, "C");
Set<Integer> textKey = map.keySet();// 集合
Iterator<Integer> keyIte = textKey.iterator();
int i=0;
while (keyIte.hasNext())
{
Integer keyStr = keyIte.next();
System.out.println("that is"+" "+keyStr+" "+i);
i++;
}
输出结果是:
that is 35436 0
that is 2324 1
that is 1213 2
遍历的顺序和输入的顺序正好相反,请问是怎么回事? 展开
map.put(1213, "A");
map.put(2324, "B");
map.put(35436, "C");
Set<Integer> textKey = map.keySet();// 集合
Iterator<Integer> keyIte = textKey.iterator();
int i=0;
while (keyIte.hasNext())
{
Integer keyStr = keyIte.next();
System.out.println("that is"+" "+keyStr+" "+i);
i++;
}
输出结果是:
that is 35436 0
that is 2324 1
that is 1213 2
遍历的顺序和输入的顺序正好相反,请问是怎么回事? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询