Collection接口
int size()
返回集合的项数
boolean isEmpty()
判断集合是否为空
boolean contains(AnyType x)
判断集合是否包含元素x
boolean add(AnyType x)
向集合添加元素x
boolean remove(AnyType x)
从集合中移除元素x
public interface Collection<AnyType> extends Iterable<AnyType>{
int size();
boolean isEmpty();
void clear();
boolean contains(AnyType x);
boolean add(AnyType x);
boolean remove(AnyType x);
java.util.Iterator<AnyType> iterator();
}
Iterator接口
boolean hasNext()
判断集合是否存在下一项
AnyType next()
判断集合是否存在下一项
public interface Iterator<AnyType>{
boolean hasNext();
AnyType next();
void remove();
}
List接口
AnyType get (int idx)
获取索引值为idx的项
AnyType set (int idx, AnyType newVal)
更改索引值为idx的项
void add(int idx, AnyType x)
在索引值为idx的地方添加一个新的项,并把其后的项向后推移一个位置
void remove(int idx)
删除索引值为idx的项
public interface List<AnyType> extends Collection<AnyType>{
AnyType get (int idx);
AnyType set (int idx, AnyType newVal);
void add(int idx, AnyType x);
void remove(int idx);
ListIterator<AnyType> listIterator(int pos);
}
**总结:**对get和set的调用花费常数时间,add代价大