Primary analysis of source code for List, Set and map

Source: Internet
Author: User

The Set, Map, and list are all leveraged using a large number of generics.

Both the list and the set inherit the collection interface. The map does not inherit any of the interfaces.


Public interface list<e> extends collection<e> public interface set<e> extends collection<e> { Public interface Map<k,v> {


Map Source Description: An object with a key value pair. A map cannot contain duplicate key-value pairs. Each key can match at most one value. This excuse can replace the dictionary class. The dictionary class is an abstract class and not an interface.

Original:

* An object which mapskeys to values. A map cannot containduplicate keys;

* Each key can map to the most one value.

*

 * <p> This interface takes the <tt> Dictionary </tt> class, which

* Was a totally abstract class rather than aninterface.

List Source Description: An ordered collection (as sequence is also widely known), the user using the list interface can precisely control the position of the inserted element. The user can access and query the elements inside by subscript. The list and set are different and can insert duplicate data.

Original:

An ordered collection (also known as a<i>sequence</i>). The user ofthis

* Interface have precise control over where inthe list all element is

* inserted. The user can access elements by their integer index (position in

* the list), and search for elements in thelist. <p>

*

* Unlike sets, lists typically allow duplicateelements.

Set: A collection that does not contain the same elements. More precisely, set does not contain a pair of elements such as the ability to e1.equals (E2), and at most only one empty element. As its name suggests, this interface simulates the concept of a mathematical set.

Original:

A collection Thatcontains no duplicate elements.  moreformally, sets contain no pair ofelements E1 and E2 such that E1.equals (E2), and at the most one null element. As implied by its name, this interface modelsthe mathematical setabstraction.

Then look at their implementation of the class ArrayList and HashMap source code, will find ArrayList inside

Encapsulated is an object array, HashMap is an array that encapsulates an inner class

ArrayList part of the construction method:


Public ArrayList (int initialcapacity) {  initialcapacity);        ... This.elementdata = new object[initialcapacity];    }

When it is instantiated, the default array size is 10:


Public ArrayList () {This        (10);}


Instead of using object for encapsulation, HashMap has an inner class entry:

There is a sentence in the construction method:

Table = new Entry[capacity];static final int default_initial_capacity = 16;

The default capacity is 16





Primary analysis of source code for List, Set, and map

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.