Package Com.mine.practice.arrtolist;import Java.util.arraylist;import Java.util.arrays;import Java.util.collections;import java.util.list;/** * Array goto List Method * @author 2014-11-17 pm 03:41:10 */public Class Arrtolist {public static void main (string[] args) {integer[] integers = {1,2,3,4,54,33}; SYSTEM.OUT.PRINTLN ("Array length:" +integers.length);//1, traversing array int len = integers.length; List<integer> List1 = new arraylist<integer> (); for (int i = 0;i<len;i++) {list1.add (integers[i]);} System.out.println ("List1:" +list1.size ());//ability to add or remove elements List1.add (1); List1.remove (1);//2, Arrays.aslist method list< Integer> list2 = arrays.aslist (integers);//The disadvantage is that elements cannot be added or deleted.Through the source we can see the abstractlist Add, remove method throws an exception.
That is, the parent class did not implement the add Delete function
List2.add (1);//list2.remove (1); System.out.println ("List2:" +list2.size ()),//3, Collections.addall method list<integer> list3 = new arraylist< Integer> (); Collections.addall (list3, integers);//ability to add or remove elements List3.add (1); List3.remove (1); System.out.println ("List3:" +list3.size ());}}
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Java round array List