国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java系列學習(十四)-集合

2019-11-15 00:56:27
字體:
來源:轉載
供稿:網友
java系列學習(十四)-集合

1.java中的集合學習

2.Collection中常用方法

1.添加功能

boolean add(E e):添加一個元素

boolean addAll(Collection<? extends E> c):添加一個集合

2.刪除功能

void clear():移除所有元素

boolean remove(Object o):移除一個指定元素

boolean removeAll(Collection<?> c):移除指定集合中的元素【只要有元素被移除,就返回true】

3.判斷功能

boolean contains(Object o):判斷集合中是否包含指定元素

boolean containsAll(Collection<?> c):判斷集合中是否包含指定集合元素【只有全部包含,才返回true】

boolean isEmpty():判斷集合是否為空

boolean equals(Object o)

4.獲取功能

Iterator<E> iterator():【父類中繼承的方法】

int hashCode():返回集合的哈希值

5.長度功能

int size():獲取集合中元素的個數

6.交集功能

boolean retainAll(Collection<?> c):兩個集合的交集【A對B做交集,結果保存在A中;只有A不變,才返回true】

7.把集合轉換成數組

Object[] toArray():把集合轉換成數組,可實現集合的遍歷

<T> T[] toArray(T[] a):

3.List特有的方法

1.添加功能

void add(int index, E element):在指定位置添加元素

boolean addAll(int index, Collection<? extends E> c):在指定位置添加集合

2.獲取功能

E get(int index):獲取指定位置的元素【與size()結合可實現遍歷】

List<E> subList(int fromIndex, int toIndex)

int indexOf(Object o)

int lastIndexOf(Object o)

3.列表迭代器

ListIterator<E> listIterator():List集合特有的迭代器

ListIterator<E> listIterator(int index)

4.刪除功能

E remove(int index):根據索引刪除元素,返回被刪除的元素

5.修改功能

E set(int index, E element):根據索引修改元素,返回被修改的元素

4.Vector特有的功能

1.添加功能

public void addElement(E obj)

public void insertElementAt(E obj, int index)

2.獲取功能

public E elementAt(int index)

public Enumeration<E> elements()

public int capacity():獲取集合的容量

public int indexOf(Object o, int index)

public int lastIndexOf(Object o, int index)

public E firstElement():獲取集合第一個元素

public E lastElement():獲取集合最后一個元素

3.復制功能

public void copyInto(Object[] anArray)

4.修改功能

public void ensureCapacity(int minCapacity):增加集合的容量

public void setElementAt(E obj, int index)

public void trimToSize():使集合等于當前大小

public void setSize(int newSize):設置集合的大小

5.移除功能

public void removeAllElements():移除所有元素,并大小設置為零

public boolean removeElement(Object obj):移除第一個元素

public void removeElementAt(int index):移除指定元素

PRotected void removeRange(int fromIndex, int toIndex):移除指定范圍元素【包括fromindex,不包括toIndex】

6.格式化功能

public String toString():返回集合的字符串形式【看源碼,重寫了】

LinkedList特有的方法:(可實現自定義棧)

public class LinkedList<E>extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, Serializable

1.添加功能

public void addFirst(E e)

public void addLast(E e)

2.獲取功能

3.public E getLast()

4public E getLast()

3.刪除功能

public E removeFirst()

public E removeLast()


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 冷水江市| 长寿区| 鸡东县| 湄潭县| 无棣县| 商城县| 克什克腾旗| 达孜县| 田东县| 台东市| 五台县| 桐城市| 佳木斯市| 龙川县| 沭阳县| 聊城市| 时尚| 弋阳县| 嘉义市| 灌南县| 盐源县| 吴桥县| 太和县| 祁连县| 井陉县| 农安县| 安徽省| 烟台市| 运城市| 锦屏县| 白朗县| 高密市| 东乡族自治县| 莲花县| 江山市| 横山县| 芮城县| 东山县| 满城县| 南皮县| 巴马|