本帖最后由 ZSY555 于 2013-3-16 01:20 编辑
- import java.util.Map;
- import java.util.HashMap;
- import java.util.Set;
- import java.util.Collection;
- import java.util.Iterator;
- class aaa{
- public static void main(String args[]){
- HashMap aa=new HashMap();
- aa.put("1","java");
- aa.put("2","VB");
- aa.put("3","VC++");
- //取出K和V的collection
- Set k1=aa.keySet();
- System.out.println("Key:");
- Iterator aaaa=k1.iterator();
- while(aaaa.hasNext()){
- System.out.println(aaaa.next());
- }
- //取出与V相对应的K
- Collection v=aa.values();
- System.out.println("Values:");
- Iterator bbbb=v.iterator();
- while(bbbb.hasNext()){
- System.out.println(bbbb.next());
- }
- //一一对应
- Set k3=aa.entrySet();
- Iterator cccc=k3.iterator();
- while(cccc.hasNext()){
- Map.Entry mp=(Map.Entry)cccc.next();
- System.out.println(mp.getKey()+":"+mp.getValue());
- }
- }
- }
- 上述代码打印出的结果为什么Key的顺序是3 2 1而不是1 2 ?求详细的解答一下
复制代码 {:soso_e149:} |