[code=java]import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
public class Other{
@Test
public void test3() throws Exception {
Map<Integer, String> map = new HashMap<Integer, String>();
//Map<Integer, String> map = new LinkedHashMap<Integer, String>();
map.put(1, "aa");
map.put(2, "bb");
map.put(3, "cc");
map.put(4, "dd");
map.put(5, "ee");
map.put(6, "ff");
map.put(7, "gg");
map.put(8, "hh");
map.put(9, "ii");
map.put(10, "jj");
map.put(11, "kk");
map.put(12, "ll");
map.put(13, "mm");
map.put(14, "nn");
map.put(15, "oo");
map.put(16, "oo");
Set<Map.Entry<Integer,String>> set = map.entrySet();
Iterator<Map.Entry<Integer,String>> iterator = set.iterator();
while(iterator.hasNext()){
Map.Entry<Integer,String> entry = iterator.next();
int key = entry.getKey();
String value = entry.getValue();
System.out.println(key + " : " + value);
}
}
}[/code]为什么 不用LinkedHashMap 输出的结果 也是按顺序的呢? 踌躇中 |