List中方法的使用

来源:互联网 发布:新加坡留学知乎 编辑:程序博客网 时间:2024/05/22 12:26
总结list的方法:List list = new List();1、list.add()在list中增加一个元素,如果只有list.add(Element el)则自动加在list的最后,并返回一个boolean值而list.add(int index,element el)则表示在index的位置插入一个元素,无返回值。2、list.addAll()用法同上,有list.addAll(Collection c)和list.addAll(int index,collection c)两种,都返回一个boolean值。collection类型扩展自java.util.Collection接口。3、list.get(int index)返回位置是index的一个元素值。4、list.retainAll(Collection c)获得所有c集合里面有的元素。5、list.toArray()把list的所有值返回到一个数组,list.toArray(T[] a) the runtime type of the returned array isthat of the specified array.不知道runtime怎么翻译。 :(6、list.subList(int fromIndex,int toIndex)返回list位置fromIndex和toIndex之间的list。7、list.clear()remove all。8、list.remove(Object o)remove第一个符合o的元素返回boolean9、list.removeAll(Collection c)删除list中所有符合c集合的元素,返回boolean10、list.set(int index,Element el)把位置为index的元素图还成el。返回先前的元素值。11、list.contains(Object o)如果list中包含o,则返回true,同样list.containsAll(Collection c)也是如此。12、list.indexOf(Object o)返回list中o的位置,为int类型。13、list.isEmpty()返回true如果list为空。14、listIterator()返回一个重复出现元素的list,list.listIterator(int index)指从index开始计算重复元素
15、list.size()
返回集合中元素的总个数

0 0
原创粉丝点击