当前位置:文档之家› Collection集合方法

Collection集合方法

Collection:
add(); remove();clear(); contains(Object o) ;isEmpty();iterator() ;
size() ; Object[] toArray() ; retainAll(Collection c)

List:extends Collection
get();ListIterator();可以倒着遍历,不过要先正着遍历。
并发修改异常。迭代器中不能使用集合增加元素。


ArrayList:extends List
无特有方法学习

Vector :extends List
跟现有集合方法名不一样的方法

LinkedList:extends List
addFirst() addLast() getFirst() getLast() removeFirst() removeLast()

Set:extends Collection
方法同Collection,无特有方法学习 特征:不能重复、无序。

HashSet:extends Set:
要重写HashCode()和equals()
哈希值与变量相关 https://www.doczj.com/doc/cc18931041.html,.HashCode()+this.age*18;

LinkedHashSet extends HashSet
由哈希表和链表结构组成
哈希表保证唯一性,链表保证有序性

TreeSet:extends Set:
能够按照某种规则排序
A:自定义对象先必须告诉TreeSet怎么排序:
自然排序,按照年龄从小到大排序
B:元素什么情况算唯一:
成员变量值都相同即为同一个元素
1:自然排序
要想实现该功能,必须implements comparable 接口再重写 compareTo方法
2:比较器排序
需要Comparator 的实现类对象 匿名内部类(new Comparator(){ public int compare(){}});
public class MyComparator implements{ public int compare(){}}

相关主题
文本预览
相关文档 最新文档