Difference list Java basic knowledge and set of interview questions and related

FIG set a family frame (map not the first comparison).
Here Insert Picture Description
Difference between the two list and set the
list and set method has differences: list may allow repeated insertion and a plurality of objects null values, and the set is not allowed; list is ordered container , and the container is set unordered
distinction List method set method
(1) repetitive object
list method may allow a duplicate object, the method does not allow duplicate objects set
(2) null element
list may be inserted into a plurality of null elements, and inserting a null set only element
(3) whether the container ordered
list is an ordered container holding the inserted sequence of each element. I.e., the output order is the input order, and the set is unordered containers, storage order can not be guaranteed for each element, by Comparator TreeSet Comparable or maintains a sort order

Three common interview questions:
? (1) Set the difference between List and the
List may contain duplicate elements, and Set contains unique items.
List is an ordered collection that maintains insertion order, and Set is an unordered collection, does not preserve insertion order.
List interface contains a legacy category: Vector class, Set interface does not have any remaining classes.
List interface may allow null values of n, but only the Set interface allows a null value.

(2) the difference between HashSet and TreeSet?
HashSet does not maintain order, and TreeSet maintain order.
HashSet represented by a hash table, and TreeSet achieved by the tree structure.
HashSet perform faster than TreeSet.
HashSet, TreeSet and supported by supported by HashMap TreeMap.

(3) Collection and Collections What is the difference?
And the difference between the Collection Collections follows: Collection is an interface, and is a Collections class. Collection interface provides a standard data structure for the function List, Set, and Queue. However, Collections class collection element for sorting and synchronization. Collection interface provides a method for the data structure, the Collections class provides static methods can be used to set various operations.

(4) Comparable and Comparator What is the difference?
Here Insert Picture Description

Published 99 original articles · won praise 2 · Views 2603

Guess you like

Origin blog.csdn.net/weixin_41588751/article/details/105107126