Set没有顺序,不可重复,类似数学中的集合
List可以重复,有顺序
在容器中,不能添加基本数据类型,得添加object
2.重写equals ,得重写hashcode。两个对象相等,它的hashcode也相等。
3.位于java.util包内。
4.Iterator接口 主要用于遍历容器,有hasNext(),next();remove()三种方法
使用 Collection c=new ArrayList();
Iterator i = c.iterator();
while(i.hasNext()){
objet ob=i.next();
i.remove();
//移除中remove 只能用Iterator的remove方法,不能用容器自身的。
}
5.Collections 类 实现了List的常用算法
shuffle()随机排列
reverse()逆序
sort()排序
binarySearch(查找的list,查找的内容)折半查找
6.Comparable接口 在java.lang.Comparable中
public int compareTo(Object obj)
返回0,this==obj
返回正数this>obj
返回负数this<obj
7.Array 读快改慢
Linked 改快读慢
Hash两者之间
8.Map hashMap TreeMap
添加数据 put(键值,值);
获取内容 get(键值) 返回object类型 ,取出来需转换
是否有该键值 containsKey(键值);
是否有该内容 containsValue(内容);
9泛型 Map<String,Integer> m=new Map<String,Integer>();
m,put("ddd",2);