List collection in Java

Source: Internet
Author: User

import java.util.arraylist;import java.util.iterator;import java.util.linkedlist;import  Java.util.list;public class listtest01 {/* *list Collection Storage element features:   1. Ordered (the list is stored with subscript): This is the order in which they are taken out or taken out in this order.   2. Repeatable  */public static void main (String[] args)  {//Create a list collection. List  l = new arraylist ();//Add L.add (+), L.add (L.add); L.add (+); L.add (250);//Traverse iterator  it = l.iterator (); while (It.hasnext ()) {System.out.println (It.next ());} /* * arraylist the bottom of the collection is an array. The array is labeled. So the ArrayList collection has a lot of its own features. ArrayList collection The underlying default initialization capacity is  10.  The capacity after enlargement is 1.5 times times that of the original capacity. Vector collection The underlying default initialization capacity is also 10. The capacity after enlargement is twice times the original capacity. If you optimize ArrayList and vectors, try to minimize the scaling operation, because the expansion requires an array copy. Array copies consume memory. It is generally recommended to specify the initialization capacity when creating the collection. *///Create List collection//list l = new arraylist (); List l1 = new linkedlist ();//add Element L1.add (123); L1.add (321); L1.add (69);//Add 555l1.add at position subscript 1 (1,555);    //obtains the first element System.out.println (l1.get (0)); SyStem.out.println ("===========================");//traversal (unique traversal method of the list collection) for (Int i=0;i<l1.size (); i++) {Object  element = l1.get (i); SYSTEM.OUT.PRINTLN (element);} Iterators can also}}


This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1669557

List collection in Java

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.