您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java集合之List代码分析

2025/6/17 4:19:32发布27次查看
list继承自collection的接口,list也是集合的一种。list是有序队列,list中的没一个元素都会有一个索引,第一个元素的索引是0,往后的元素的索引值依次+1,list中允许有重复的元素。
list框架:
list接口源码:
public interface list<e> extends collection<e> { int size();//大小 boolean isempty();//判断是否为空 boolean contains(object o);//判断是否包含某个对象 iterator<e> iterator();//返回迭代对象 object[] toarray(); //返回对象数组 <t> t[] toarray(t[] a);//对象数组 boolean add(e e);//添加某个对象 boolean remove(object o);//删除某个对象 boolean containsall(collection<?> c); // 是否包含某个collection的所有对象 boolean addall(collection<? extends e> c);//将collection对象追加到list中 boolean addall(int index, collection<? extends e> c);//在某个位置将collection对象追加到list中 boolean removeall(collection<?> c);//去掉collection中所包含的对象 boolean retainall(collection<?> c);//去掉不包含在collection中所包含的对象 default void replaceall(unaryoperator<e> operator) { objects.requirenonnull(operator); final listiterator<e> li = this.listiterator(); while (li.hasnext()) { li.set(operator.apply(li.next())); } } @suppresswarnings({"unchecked", "rawtypes"}) default void sort(comparator<? super e> c) { object[] a = this.toarray(); arrays.sort(a, (comparator) c); listiterator<e> i = this.listiterator(); for (object e : a) { i.next(); i.set((e) e); } } void clear();//删除所有对象 boolean equals(object o);//判断两个list是否相同 int hashcode();//返回list的hashcode e get(int index);//返回某个位置的对象 e set(int index, e element);//替换某个位置的对象 void add(int index, e element);//在某个位置添加对象 e remove(int index);//删除某个位置的对象 int indexof(object o);//返回某个对象在list中的位置 int lastindexof(object o);//list中最后一个对象的坐标 listiterator<e> listiterator();//返回整个list的迭代 listiterator<e> listiterator(int index); //从某个位置开始返回list的迭代 list<e> sublist(int fromindex, int toindex);//截取部分list @override default spliterator<e> spliterator() { return spliterators.spliterator(this, spliterator.ordered); } }
以上就是java集合之list代码分析的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product