集合的父子类关系

时间:2025-02-16 09:59:47
一.Collection的父子类关系
(java集合的*接口之一)——实现此接口的类可以使用新的for循环

(接口,遍历器)ListIterator
方法:hasNext();next();remove();

(接口,继承Iterable)
方法:
add();addAll();remove();removeAll();contains();containsAll();
size();isEmpty();toArray();clear();iterator();

(抽象类,继承Collection并重写实现里面的方法)

二.List的父子类关系
(接口,继承Collection并包含里面的所有方法)——可重复,并且有序
方法(可以通过下标操作元素):
get(i);set(i,p);add(i,p);remove(i);
indexOf(p);lastIndexOf();subList(i,j);

2.工具类Collections——为List提供排序方法
sort(list);——返回值int型
(list,new Comparator<String>() {
public int compare(String o1,String o2) {
return ()-();
}
});

(抽象类,实现接口List并重写实现里面的方法,继承AbstractCollection)

(类,继承AbstractList并重写实现里面的方法)

三.队列Queue的父子类关系——遵循“先进先出”原则
(接口,继承Collection)
方法:
offer(p);poll();peek();

(抽象类,继承AbstractList)

(类,继承AbstractSequentialList)

四.双端队列Deque的父子类关系
(接口,继承Queue并重写实现里面的方法)
方法:
offerFirst()——push()——入栈;pollFirst()——pop()——出栈;
offerLast();pollLast();
peekFirst();peekLast();

(抽象类,继承AbstractList)

(类,继承AbstractSequentialList)