Java Learning Diary------Collection

Source: Internet
Author: User

Collection
* Collection Interface
* List interface: stored in an orderly, repeatable element
* ArrayList (the main implementation class is the underlying implementation is an array), LinkedList (the underlying implementation is a list), Vector (Old implementation class JDk1.0, thread-safe but inefficient)
* Set interface: Stores unordered, non-repeatable elements
* HashSet, Linkedhashset, TreeSet
* MAP: Stores data for "key-value" pairs
* HashMap, Linkedhashmap, TreeMap, Hashtable (-properties)

Importjava.util.ArrayList;Importjava.util.List;Importorg.junit.Test; Public classtestlist {@Test Public voidtestList2 () {List List=NewArrayList (); List.add (123); List.add (NewString ("AA"));        SYSTEM.OUT.PRINTLN (list); System.out.println (List.indexof (123)); System.out.println (List.lastindexof (123)); System.out.println (List.indexof (123) ==list.lastindexof (123)); List List1= List.sublist (1, 2);    System.out.println (List1); } @Test Public voidTestList1 () {List List=NewArrayList (); List.add (123); List.add (NewString ("AA"));        SYSTEM.OUT.PRINTLN (list); List.add (0, 555);        SYSTEM.OUT.PRINTLN (list); Object obj= List.get (1); System.out.println (List.get (0)); List.set (0, 888); System.out.println (List.get (0));        SYSTEM.OUT.PRINTLN (list);    System.out.println (List.size ()); }}

List Common methods: Add: (Add ()) Delete: (remove ())
* Change: (set (int index,object elem)) Check: (Get (int index))
* Plug (add (int index,object elem)) Length (size ())
* int indexOf (Object obj): Returns the position of the first occurrence of obj in the collection, if no return-1
* int lastIndexOf (Object obj): Returns the position of the last occurrence of obj in the collection, if no return-1
* List sublist (int fromindex,int toindex); Returns a sub List from FromIndex to Toindex

Java Learning Diary------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.