Collection裡的方法

2021-09-27 03:13:54 字數 531 閱讀 9541

@test

public void testcollextion1()

@test

public void testcollection2()

@test

public void testcollection3()

返回乙個iterator介面實現類的物件,進而實現集合的遍歷

iterator iterator = coll.iterator();

//方式一:不用

// system.out.println(iterator.next());

//方式二:不用

// for(int i = 0;i < coll.size();i++)

//方式三:使用 迭代器iterator實現集合的遍歷

while(iterator.hasnext())

}

//使用增強for迴圈實現集合的遍歷

@test

public void testfor()

}

Collection介面 常用方法

1 add 方法boolean add e e 向集合中插入乙個元素 collection c newarraylist c.add hello world c.add 100 c.add 3.14 c.add true 2 clear 方法void clear 清空集合中的元素,從這個集合中移除所...

集合collection介面方法的訓練

public class vc public static void main string args 也可以使用for迴圈實現迭代 for iteratoriter1 coll.iterator iter1.hasnext 集合可以存任何型別的元素最好在使用集合最好加上型別,這樣就不需要強轉了 c...

集合中Collection方法詳解

有乙個cell類,如下 public class cell implements comparable override public string tostring override public boolean equals object obj if obj this if obj insta...