集合-List

List集合常用方法

 

标号  返回值类型 方法名 说明 英文解释
1  添加 boolean add(E e) 向列表的尾部添加指定的元素,返回值表示添加是否成功  
2  添加 void add(int index,E element)

在指定的下标中插入指定的元素

index:下标     element:元素
3  添加 boolean addAll(Collection c)  添加指定 collection 中的所有元素到此列表的结尾,顺序是指定 collection 的迭代器返回这些元素的顺序  
  查询 E get(int index) 返回列表中指定位置的元素  
  更改 E set(int index, E element) 用指定元素替换列表中指定位置的元素  
  删除 E remove(int index) 移除列表中指定位置的元素  
  删除 boolean remove(Object o) 从此列表中移除第一次出现的指定元素(如果存在)  
  删除 boolean  removeAll(Collection<?> c)  从列表中移除指定 collection 中包含的其所有元素  
  集合的长度 int size() 返回列当前表中的元素的个数  
  清除所有元素 void  clear() 从列表中移除所有元素(可选操作)。  
 包含 元素/对象 boolean  contains(Object o) 如果列表包含指定的元素,则返回 true。  
 包含集合 boolean  containsAll(Collection c)  如果列表包含指定 collection 的所有元素,则返回 true。  
  boolean  equals(Object o) 比较指定的对象与列表是否相等。  
  int hashCode() 返回列表的哈希码值。  
  boolean  isEmpty() 如果列表不包含元素,则返回 true。  
  Iterator<E> iterator()  返回按适当顺序在列表的元素上进行迭代的迭代器。  
  ListIterator<E>  listIterator(int )  返回此列表元素的列表迭代器(按适当顺序)。  
  boolean retainAll(Collection<?> c)  仅在列表中保留指定 collection 中所包含的元素(可选操作)。  
  Object[] toArray() 返回按适当顺序包含列表中的所有元素的数组(从第一个元素到最后一个元素)。  
  <T> T[] toArray(T[] a) 返回按适当顺序(从第一个元素到最后一个元素)包含列表中所有元素的数组;返回数组的运行时类型是指定 数组的运行时类型。  
  int indexOf(Object o) 返回此列表中第一次出现的指定元素的索引;如果此列表不包含该元素,则返回 -1。  
  int lastIndexOf(Object o) 返回此列表中最后出现的指定元素的索引;如果列表不包含此元素,则返回 -1。  
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 public boolean add(E e): 把给定的对象添加到当前集合中 。
 public boolean add(Colllection c):将c作为一个元素添加到集合中
 public boolean addAll(Collection c):将c集合的每个元素加到当前集合中
 public void clear() :清空集合中所有的元素。
 public boolean remove(E e): 把给定的对象在当前集合中删除。
 public boolean removeAll(Colllection c): 从当前集合中删除c集合中的元素。
 public boolean contains(E e): 判断当前集合中是否包含给定的对象。
 public boolean containsAll(Colllection c): 判断c是否是当前集合的子集。
 public boolean isEmpty(): 判断当前集合是否为空。
 public int size(): 返回集合中元素的个数。
 public Object[] toArray(): 把集合中的元素,存储到数组中。
- public boolean add(E e): 把给定的对象添加到当前集合中 。
- public boolean add(Colllection c):将c作为一个元素添加到集合中
- public boolean addAll(Collection c):将c集合的每个元素加到当前集合中
- public void clear() :清空集合中所有的元素。
- public boolean remove(E e): 把给定的对象在当前集合中删除。
- public boolean removeAll(Colllection c): 从当前集合中删除c集合中的元素。
- public boolean contains(E e): 判断当前集合中是否包含给定的对象。
- public boolean containsAll(Colllection c): 判断c是否是当前集合的子集。
- public boolean isEmpty(): 判断当前集合是否为空。
- public int size(): 返回集合中元素的个数。
- public Object[] toArray(): 把集合中的元素,存储到数组中。

 

posted @ 2022-08-17 23:02  向大海  阅读(25)  评论(0编辑  收藏  举报