collection的子接口包括:List和set
其中list又有arraylist、linkedlist、vector;set又有hashset和treeset
collection方法摘要:(他们所共有的方法)
add()
addall()
clear()
remove()
removeall()即为求补
contains()
containsAll()
equals() hashCode()
isEmpty()
size()
retainAll()j即为求交
iterator()
list所特有的方法:
另外还有Stack和queue,都可用linkedlist实现:linkedlist方法中有不仅有addFirst()、getFirst()、removeFirst()和对应的XXlast()方法之外,还有push()和pop()方法,难道它可以直接当做栈使用吗?jdk1.6之后又有用offer代替add,用poll代替remove,用peek代替get,其中remove和get当列表为空时,会有异常,NoSuchElementException。而代替后的方法,没有的话则会返回空。add(index,e)
addAll(index,Collection)
remove(index)
set(index,element)
get(index)
sublist(from,to)
listIterator()
不仅可以用迭代器访问元素,只能对元素进行判断,取出,删除操作
还可以通过列表迭代器进行访问,可以对元素进行添加和修改
还可以通过
for(int x=0;x<al.size();x++)
{
print(al.get(x));
}来访问arraylist的底层使用的是数组结构,linkedlist使用的是链表结构,以前 的vector也是数组结构,只不过是线程同步的,我们推荐使用arrayList,多线程是自己加锁