Java Learning notes----container

Source: Internet
Author: User

First, what is the Java collections framework? The Java collections framework includes a number of collection interfaces and the implementation classes of these interfaces and the algorithms that manipulate them (such as: sort, find, reverse, replace, copy, take the smallest element, take the largest element).

It mainly provides data structures such as list, Queue, Set, Stack, map and so on. The list, Queue, Set, and stack are all inherited from the collection interface.

    • Set represents a collection.

      Main features. The elements in the collection are unique.

      The interface has two implementation classes: HashSet and TreeSet. The TreeSet implements the SortedSet interface, so the elements in the TreeSet container are ordered.

    • The list is an orderly collection. It saves objects in the order in which they are entered, so it can precisely control where each element in the list is inserted and deleted.

      At the same time, it is able to save repeated objects. LinkedList, ArrayList, vector all implement the list interface.

    • Map provides a data structure that maps a key to a value. It can save key-value pairs. But key is the only one. The implementation classes for this interface are: HashMap, TreeMap, Linkedhashmap, Weakhashmap, and Identityhashmap.

Second, what is an iterator? That is, iterator, which is an object. The ability to traverse and select objects in a sequence. Note Iterator in the process of traversing an object, it is assumed that adding or removing the container will change the number of objects in the container, causing an exception to be thrown.
Listierator inherits from iterator. Specifically for list, the ability to traverse the list from two directions, supporting element changes at the same time. Iii. What is the difference between collection and collections? Collection is a collection interface.


Collections is a wrapper class for a collection class that provides a series of static methods for searching, sorting, threading, and so on for various collections. Most of these methods are used to process linear tables. Collections is a tool class. cannot be instantiated.

The demo sample code is as follows:
Import java.util.*;p ublic class test{public static void Main (String args[]) {list<integer> List = new linkedlist< Integer> (); int array[]={1,7,2,3};for (int i=0;i<array.length;i++) {List.add (new Integer (Array[i]));} Collections.sort (list); for (int i=0;i<list.size (); i++) {System.out.println (List.get (i));}}}



Program execution results such as the following: 1237

Java Learning notes----container

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.