标签:imp hashmap put set 增强 pac stat obj pre
1 package Z3_1; 2 3 import java.util.*; 4 5 public class QWE { 6 public static void main(String[] args) { 7 Map mijia=new HashMap(); 8 mijia.put("cn", "china"); 9 mijia.put("uk", "ufo"); 10 //方式一 增强for 11 System.out.println("方式一增强for"); 12 Set ks=mijia.keySet();//keyset 13 for (Object object : ks) { 14 System.out.println(mijia.get(object)); 15 } 16 //方式二 迭代器Iterator 17 System.out.println("方式二,迭代器Iteration"); 18 Iterator it=ks.iterator(); 19 while(it.hasNext()){ 20 String sk=(String)it.next(); 21 System.out.println(sk+"=="+mijia.get(sk)); 22 } 23 24 25 // Set set =mapContries.entrySte(); 26 // for (Object object : set) { 27 // Map.Entryentry=(Map.Entry); 28 // entry.getKey();//String 29 // entry.getValue(); 30 // } 31 32 33 34 // //遍历方式三 35 Dog dog1=new Dog("mijia","5714"); 36 Dog dog2=new Dog("qwe","123"); 37 Dog dog3=new Dog("sad","456"); 38 Dog []dogg=new Dog[3]; 39 40 HashMap hm=new HashMap<>(); 41 hm.put(1, dog1); 42 hm.put(2, dog2); 43 hm.put(3, dog3); 44 Set set =hm.entrySet(); 45 Iterator itt=set.iterator(); 46 while(itt.hasNext()) 47 { 48 Map.Entry en=(Map.Entry)itt.next(); 49 Dog dog =(Dog)en.getValue(); 50 System.out.println(en.getKey()+" "+en.getValue()); 51 } 52 } 53 }
标签:imp hashmap put set 增强 pac stat obj pre
原文地址:https://www.cnblogs.com/mj5714/p/9456905.html