Java Basic Knowledge Enhancement Collection Framework note 15:list Collection features

Source: Internet
Author: User

1. Features of the list collection

The list itself is also an interface, as follows:

1   Public  Interface  List<e>  extends collection<e>

(1) List is an ordered collection (also known as a sequence), where the user of this interface can precisely control where each element in the list is inserted, and the user can access the element based on the integer index of the element (in the list) and search for the elements in the list.

(2) Unlike set,list lists usually allow repeating elements .

2. code example:

1  Packagecn.itcast_01;2 3 Importjava.util.ArrayList;4 ImportJava.util.Iterator;5 Importjava.util.List;6 7 /*8 * Features of the list collection:9 * Ordered (same as stored and removed elements), repeatable. Ten  */ One  Public classListDemo2 { A      Public Static voidMain (string[] args) { -         //To create a collection object -List List =NewArrayList (); the  -         //Storage Elements -List.add ("Hello"); -List.add ("World"); +List.add ("Java"); -List.add ("Java ee"); +List.add ("Android"); AList.add ("Java ee"); atList.add ("Android"); -  -         //iterating through the collection -Iterator it =list.iterator (); -          while(It.hasnext ()) { -String s =(String) It.next (); in System.out.println (s); -         } to     } +}

The results are as follows:

Java Basic Knowledge Enhancement Collection Framework note 15:list Collection features

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.