<java>collection Interface and List interface

Source: Internet
Author: User

A

The Java language designer has made some specifications (interfaces) and implementations (classes that implement interfaces) for commonly used data structures and algorithms. All abstract data structures and operations (algorithms) are collectively referred to as the collection framework.

The collection in Java can be broadly divided into three major systems: List, Set, MAp. The list represents an ordered set, the set represents an unordered set, and a map represents a collection of mapping relationships.

Two "diagram below

Three "Detailed introduction:

List:

Features: Ordered and repeatable.

Two important implementation classes: ArrayList and LinkedList

1.ArrayList features are ordered and repeatable

2.LinkedList is a doubly linked list structure.

Set:

The set interface inherits from the collection interface, which does not provide an additional method, but the elements in the collection class that implement the set interface are unordered and non-repeatable.

Features: unordered and non-repeatable.

MAP:

Map is also an interface, but does not inherit the collection interface. This interface describes a key-to-value mapping that is never duplicated. The map interface is used to maintain key/value pairs (Key/value pairs).

Feature: It describes a mapping of key-to-value values that are never duplicated.

Two important implementation classes: HashMap and TreeMap

1.HashMap, a key corresponds to a value. The ordering of elements in HashMap is not fixed. More suitable for inserting, deleting, and positioning elements.

The elements in the 2.treemap,treemap maintain some sort of fixed order. More suitable for sequential traversal of elements.

Iterator:

All container classes that implement the collection interface have a iterator method that returns an object that implements the iterator interface. The iterator object is called an iterator,

The iterator interface method iterates through each element of the collection in an iterative manner and removes the appropriate element from the collection, which is commonly used for traversal .

The code demonstrates the following:

 Public  Static  void Main (string[] args) {        Collectionnew arraylist<>();        A.add ("A");        A.add ("B");        A.add ("C");        Iterator<String> B = a.iterator (); // Create an iterator         while (B.hasnext ()) {// Determine if there is a next element            System.out.println (B.next ()); // returns the element         }    }

Give you a sugar.

<java>collection interface and list interface

Related Article

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.