list
Student s1=new Student("张三",1); Student s2=new Student("李四",2); Student s3=new Student("王五",2); Listlist=new ArrayList (); list.add(s1); list.add(s2); list.add(s3); for(int i=0;i
map 遍历注意Entry()
HashMapmap=new HashMap(); map.put(1, "aaa"); map.put(2, "bbb"); map.put(3, "ccc"); //map.remove(3);// for(Map.Entry entry : map.entrySet())//遍历反法1// {// System.out.println(entry.getKey()+entry.getValue());// } //遍历方法2 for(Integer key :map.keySet()) { System.out.println(key); } for(String val :map.values()) { System.out.println(val); } //遍历方法3 Iterator > it=map.entrySet().iterator(); while(it.hasNext()) { Map.Entry ma=it.next(); System.out.println(ma.getKey()); System.out.println(ma.getValue()); } }