list集合
**继承了Collection接口
特点:有序,可重复
常见实现类 ArrayList Vector LinkedList
set集合
**继承了Collection接口
特点:无序,元素不重复,重复添加会覆盖.同理,集合中最多有一个null
常见实现类 HashSet
map集合
特点:以键值对方式存储,key不可重复 value可重复
常见实现类 HashMap
map集合的遍历
方法一:
public void get(Map<String, String> map) {
Collection<String> c = map.values();
Iterator it = c.iterator();
for (; it.hasNext();) {
System.out.println(it.next());
}
}方法二:
public void getByKeySet(Map<String, String> map) {
Set<String> key = map.keySet();
for (Iterator it = key.iterator(); it.hasNext();) {
String s = (String) it.next();
System.out.println(map.get(s));
}
}方法三:
public void getByEntry(Map<String, String> map) {
Set<Map.Entry<String, String>> set = map.entrySet();
for(Iterator<Map.Entry<String, String>> it = set.iterator(); it.hasNext();){
Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
System.out.println(entry.getKey() + " : " + entry.getValue());
}
}
}本文出自 “QinGuan” 博客,请务必保留此出处http://11083953.blog.51cto.com/11073953/1734479
原文:http://11083953.blog.51cto.com/11073953/1734479