用HashMap存储信息、
//HashMap
System.out.println("------HashMap无序输出------");
HashMap<String,String> hsMap=new HashMap<String,String>();
hsMap.put("3", "Value3");
hsMap.put("1", "Value1");
hsMap.put("2", "Value2");
hsMap.put("b", "ValueB");
hsMap.put("a", "ValueA"); //在此映射中关联指定值与指定键。
Iterator<Entry<String, String>> it = hsMap.entrySet().iterator(); // 返回此映射所包含的映射关系的 Set 视图。
while (it.hasNext()) {
@SuppressWarnings("rawtypes")
Entry e = (Entry) it.next();
System.out.println("Key: " + e.getKey() + "--Value: " + e.getValue());
}
TreeMap
System.out.println("------TreeMap按Key排序输出------");
TreeMap<String,String> teMap=new TreeMap<String,String>();
teMap.put("3", "Value3");
teMap.put("1", "Value1");
teMap.put("2", "Value2");
teMap.put("b", "ValueB");
teMap.put("a", "ValueA");
//Set<Entry<String, String>> set3 = teMap.entrySet();
//Iterator<String,String> tit = teMap.entrySet().iterator();
Iterator<Entry<String, String>> tit = teMap.entrySet().iterator();
while (tit.hasNext()) {
Entry<String, String> e = tit.next();
System.out.println("Key: " + e.getKey() + "--Value: " + e.getValue());
}
}