package package1;import java.util.ArrayList;import java.util.List;public class Demo3 { public static void main(String[] args) { Listall=new ArrayList (); System.out.println(all.isEmpty()); all.add("a"); all.add("b"); all.add("c"); System.out.println(all.isEmpty()); System.out.println(all); System.out.println("集合长度:"+all.size()); //循环输出的两种方式比较 for(int i=0;i
LinkedList链式集合列表(不常用,经常会用ArrayList)
package package1;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;public class Demo3 { public static void main(String[] args) { LinkedListall=new LinkedList (); System.out.println(all.isEmpty()); all.add("a"); all.add("b"); all.add("c"); all.addFirst("hclals"); all.addLast("hajljsk"); System.out.println(all); System.out.println(all.poll()); }}
set:
package package1;import java.util.ArrayList;import java.util.HashSet;import java.util.LinkedList;import java.util.List;import java.util.Set;public class Demo3 { public static void main(String[] args) { Setall=new HashSet (); //hashset无序但不允许重复,treeset不允许重复 all.add("a"); all.add("b"); all.add("c"); all.add("c");//重复元素不保存 System.out.println(all); }}