Collection Framework (features of the list collection)

Source: Internet
Author: User

List interface Overview (its elements can be duplicated)

the Orderly collection (also known as a sequence ). Users of this interface can precisely control the insertion position of each element in the list. The user can access the element based on the integer index of the element (where it is located in the list) and search for the elements in the list.

Unlike set, a list usually allows repeating elements.

List case

Store strings and Traverse

Store custom objects and traverse


Package cn.itcast_01;


Import java.util.ArrayList;

Import Java.util.Iterator;

Import java.util.List;


/*

* features of the list collection:

* ordered (same as stored and removed elements), repeatable.

*/

public class ListDemo2 {

public static void Main (string[] args) {

To create a collection object

List List = new ArrayList ();


Storage elements

List.add ("Hello");

List.add ("World");

List.add ("Java");

List.add ("Java ee");

List.add ("Android");

List.add ("Java ee");

List.add ("Android");


Iterating through the collection

Iterator it = List.iterator ();

while (It.hasnext ()) {

string s = (string) it.next ();

System.out.println (s);

}

}

}


This article from "GD" blog, reproduced please contact the author!

Collection Framework (features of the list collection)

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.