What is the fundamental difference between the Set<E>
and List<E>
interfaces?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
List:
List
s generally allow duplicate objects.List
s must be ordered, and are therefore accessible by index.Implementation classes include:
ArrayList
,LinkedList
,Vector
Set:
Set
s do not allow duplicate objects. Most implementations are unordered, but it is implementation specific.Implementation classes include:
HashSet
(unordered),LinkedHashSet
(ordered),TreeSet
(ordered by natural order or by provided comparator)1.List allows duplicate values and set does'nt allow duplicates
2.List maintains the order in which you inserted elements in to the list Set does'nt maintain order. 3.List is an ordered sequence of elements whereas Set is a distinct list of elements which is unordered.
Set:
Cannot have duplicate values Ordering depends on implementation. By default it is not ordered Cannot have access by index
List:
Can have duplicate values Ordered by default Can have access by index
List
is an ordered sequence of elements whereasSet
is a distinct list of elements which is unordered (thank you, Quinn Taylor).List<E>:
Set<E>:
A Set cannot contain duplicate elements while a List can. A List (in Java) also implies order.
Ordering... a list has an order, a set does not.