public class KeysetAndEntrySet {
    public static void main(String[] args) {
        Map map1 = new HashMap();
        Map map2  =  new TreeMap();
        
        map1.put("name1", "Christ Bosh");
        map1.put("name2","Kobe Bryant");
        map1.put("name3", "Lebron James");
        map1.put("name4", "Dwany Wade");
        
        map2.put("name1", "Christ Bosh");
        map2.put("name2","Kobe Bryant");
        map2.put("name3", "Lebron James");
        map2.put("name4", "Dwany Wade");
        
        Set set =  map1.entrySet();
        Iterator it = set.iterator();
        while(it.hasNext()){
            Map.Entry next = (Entry) it.next();
//            System.out.println("========"+next.toString()+"**********");
//            String str = it.next().toString();
//            int index = str.indexOf("=");
//            System.out.println(str.substring(0,index)+" "+str.substring(index+1));
            Object key = next.getKey();
            Object value = next.getValue();
            System.out.println(key+"++++"+value);
        }
        System.out.println("------------------------------------");
        Set set2  = map2.keySet();
        Iterator it2 = set2.iterator();
        while(it2.hasNext()){
            Object ob = it2.next();
            System.out.println(ob.toString()+" "+map2.get(ob));
        }
    }
}

相关文章:

  • 2022-12-23
  • 2021-07-04
  • 2021-09-22
  • 2022-01-31
  • 2021-07-25
  • 2021-09-02
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2021-05-21
  • 2021-09-24
  • 2021-06-12
  • 2022-12-23
  • 2021-12-14
相关资源
相似解决方案