Java Review the list interface of the collection class

Source: Internet
Author: User

List as ordered and repeatable lists

The class that implements the list interface is primarily ArrayList

The following is the test code for ArrayList

Importjava.util.ArrayList; Public classDemo4 { Public Static voidmain (String [] args) {ArrayList A1=NewArrayList (); A1.add (NewInteger (11)); A1.add (NewInteger (23)); A1.add (NewInteger (65)); A1.add (NewInteger (28)); A1.add (NewInteger (72)); A1.add (NewInteger (98));                SYSTEM.OUT.PRINTLN (A1); //Conversion GroupObject a[] =A1.toarray (); intsum = 0;  for(inti=0; i<a.length; i++) Sum+=((Integer) a[i]). Intvalue (); System.out.println ("Sum:" +sum); }}

Code Analysis:

Instantiate an ArrayList object first A1

Adding elements to the Add () method

Output the entire list

Then convert the collection A1 to the array, using the method of ToArray ()

The Intvalue () method is used in the calculation of the sum of the arrays: you can convert the wrapper type to the underlying type value

Finish

Java Review the list interface of the collection class

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.