一.总体分类
LinkedList
ArrayList
Vector---Stack
2. Set
HashSet
TreeSet
二.Map接口:元素以键值对的方式存放(无序)
HashMap:键不能重复,当添加重复的时候,会将原来的值覆盖掉
键和值都可为空
HashTable:线程安全
键不能空,值能空
TreeMap:自然顺序,键要兼容
键和值都不能为空
类必须实现Comparable接口,重写compareTo方法
HashMap
HashMap hm=new HashMap(); hm.put("ss",15);obj类型 hm.put("ss",20);//键只有一个。每个省一个省会 hm.get(ss);//围绕key hm.containsKey(); hm.remove(); Collection l=hm.values();//获取值
遍历方式比较特殊,将键值对封装为一个类:hm.entrySet()方法。
Set set=hm.entrySet(); for(Object o:set){ Entry e=(Entry)o;//利用entry类的getValue和getKey方法 syso(e.getValue()+e.getKey); } //方法2:hashMap的get方法 for(Object o:set){ syso(o+" "+ hm.get(o)); }
HashSet的底层是hashMap写的
三.Collection和泛型简介
封装了许多静态方法,如add remove等
数组的排序用Arrays.sort();
而集合的排序用Collections.sort();
泛型:用于规定集合中的数据类型
ArrayList<String> a=new ArrayList<String>();//只能放字符串到al中
HashMap<String,String>hm=new HashMap<String ,String>();
原文:https://www.cnblogs.com/anzhilanxiao/p/10587756.html