Importjava.util.ArrayList;Importjava.util.Arrays;ImportJava.util.HashSet;Importjava.util.List; Public classArraysaslistdemo { Public Static voidMain (string[] args) {List<String> Source1 =NewArraylist<string> (Arrays.aslist ("1", "2", "3")); ArrayList<String> Source2 =NewArraylist<string> (Arrays.aslist ("5", "62", "3")); Source2.removeall (SOURCE1); System.out.println (SOURCE2);//arrays.aslist ("1", "2", "3"). Remove ("1");//will error. Because the Remove method is not implemented in Arrays$arraylistSystem.out.println (Source1.containsall (SOURCE2)); HashSet<String> total =NewHashset<string>(); Total.addall (SOURCE1); Total.addall (SOURCE2); System.out.println (Total.size ()> (source1.size () +source2.size ())); System.out.println (Total.size ()< (Source1.size () +source2.size ())); }}
//Misc /*** Returns a fixed-size list backed by the specified array. (Changes to * The returned list "write through" to the array.) This method acts * as bridge between array-based and collection-based APIs, in * combination with {@linkCollection#toarray}. The returned list is * Serializable and implements {@linkrandomaccess}. * * <p>this method also provides a convenient-to-Create a fixed-size * list initialized to contain sever Al elements: * <pre> * list< String> Stooges = Arrays.aslist ("Larry", "Moe", "Curly"); * </pre> * *@parama The array by which the list would be backed *@returnA list view of the specified array*/ Public Static<T> list<t>aslist (T ... a) {return NewArraylist<t>(a); } /** * @serialinclude*/ Private Static classArraylist<e>extendsAbstractlist<e>Implementsrandomaccess, java.io.Serializable {Private Static Final LongSerialversionuid = -2764017481108945198l; Private Finale[] A; ArrayList (e[] array) {if(array==NULL) Throw NewNullPointerException (); A=Array; }
What's the matter with arrays.aslist?