java--Set Classic face question

Source: Internet
Author: User

    • The difference between list and set, map.

List:

1. Duplicate objects can be allowed.

2. You can insert multiple null elements.

3. Is an ordered container that maintains the order in which each element is inserted, and the order in which the output is inserted.

4. Common implementation classes are ArrayList, LinkedList, and vectors. ArrayList is the most popular, providing discretionary access using indexes, while LinkedList is more appropriate for situations where elements are often required to be added or removed from a list.

Set:

1. Duplicate objects are not allowed

2. Unordered containers, you cannot guarantee the order in which each element is stored, TreeSet maintains a sort order by Comparator or comparable.

3. Only one null element is allowed

Some of the most popular implementations of the 4.Set interface are HashSet, Linkedhashset, and TreeSet. The most popular is the HASHMAP implementation-based Hashset;treeset also implements the SortedSet interface, so TreeSet is an ordered container sorted according to its compare () and compareTo () definition

MAP:

1.Map is not a sub-interface or implementation class of collection. Map is an interface.

Each Entry in 2.Map holds two objects, which is a key value, and Map may hold the same value object but the key object must be unique.

3. TreeMap also maintains a sort order by Comparator or comparable.

4. You can have a random null value in Map, but there can be at most one null key. Some of the most popular implementations of the 5.Map interface are HashMap, Linkedhashmap, Hashtable, and TreeMap. (HashMap, TreeMap most commonly used )

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////

    • Is there a difference between LinkedList and ArrayList?

1.ArrayList is to implement a data structure based on a dynamic array, LinkedList a linked list-based data structure. (linkedlist is a doubly linked list with next and previous)
2. for random access to get and set,ArrayList Feel better than LinkedListbecause linkedlist want to move the pointer.  
3. for new and deleted operations add and remove,linedlist comparative advantage, because ArrayList you want to move the data.

java--Set Classic face question

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.