Collection接口
|----List接口:存储有序的,可以重复的元素
|----ArrayList(主要的实现类)、LinkedList、Vector
|----Set接口:存储无序的,不可重复的元素
|----HashSet、LinkedHashSet、TreeSet
Map接口:存储“键-值”对的数据
|----HashMap、LinkedHashMap、TreeMap、Hashtable(子类:Propertries)
List集合里添加了一些根据索引来操作集合元素的方法:
void add(int index,Object ele):在指定的索引位置index添加元素ele
boolean addAll(int index,Collection eles)
Object get(int index):获取指定索引的元素
int indexOf(Object obj):返回obj在集合中首次出现的位置。没有的话,返回-1。integer和string都重写好了
int lastIndexOf(Object obj):返回obj在集合中最后一次出现的位置。没有的 话,返回-1。
Object remove(int index):删除指定索引位置的元素
Object set(int index,Object ele):设置指定索引位置的元素为ele
List subList(int fromIndex,int toIndex):返回从fromIndex到toIndex结束的左闭右开(包含左不包含右)一个子list
List常用方法:
增 add(Object obj)
插 add(int index,Object ele)
删 remove
改 set(int index,Object obj)
查 get(int index)
长度 size()
LinkedList:
LinkedList链指针,对于频繁的插入、删除操作,建议选择他。
ArrayList在堆空间还是拿数组放一起的。
LinkedList不一定连续,下一块不一定连续,拿指针指向,是拿链表来存的,遍历还是有索引的。
Vector:
古老的实现类,线程安全的,太老太慢了,不用了