Java round array List

Source: Internet
Author: User

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

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.