What's the matter with arrays.aslist?

Source: Internet
Author: User
Tags addall

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&lt; String&gt;     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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.