The difference between list and ArrayList, map and HashMap

Source: Internet
Author: User

List is an interface, and the list attribute is ordered, ensuring that elements are preserved in a certain order.
ArrayList is its implementation class, which is a list implemented with arrays.
Map is an interface, and the map attribute is to find objects based on an object.
HashMap is its implementation class, HashMap is implemented with a hash table map, is to use the object's Hashcode (Hashcode () is the method of object) for fast hash lookup. (for hash lookup, see << data structure >>)


In general, if not necessary, the recommended code only deals with the List,map interface.
For example: List list = new ArrayList ();
The reason for this is that the list is equivalent to a generic implementation, and if you want to change the type of the list, you only need to:
List List = new LinkedList ();//linkedlist is also the implementation class of the list, and also the brother class of ArrayList
In this way, there is no need to modify other code, which is the elegance of interface programming.
Another example of this is the following declaration in the method of the class:
private void Domyaction (List list) {}
This method can handle all the classes that implement the list interface, and implement generic functions to some extent.


You can customize your custom class by implementing List,map (or collection) if you feel that Arraylist,hashmap's performance does not meet your needs when developing.

The difference between list and ArrayList, map and HashMap

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.