Collection - + add(all), remove(All, if(if satisfy filter)), contains(All), clear, equals, hashCode, isEmpty, retainAll(Op, return only present in) , size, stream, toArray
List - 1. ordered sequence.
- access by index as well as iterating.
- allows duplicates
- lists are equal if they are same size and in same order.
- get(index), set(index) - replace, add(index) - add and shift, remove(index), indexOf(object)
ArrayList
Resizeable-array implementation, permits nulls,
is roughly equivalent to Vector, besides is not synchronized
-
-
fail-fast, not synchronized
LinkedList
Doubly linked List, it permits nulls
-
-
operations with index based traverse list from beginning or from the end - depend which one is closer
As a queue: offer (last, first), peek (last, first), poll (last, first), pop (when used as stack)
-
-
Set - 1. no duplicates.
- the most one null element.
- Equals() - check if sets are same size and if every element is contained in second (no order)
HashSet
uses HashMap (Default LF is created with 0.75 and 16 capacity) instance under the hood. We can set while creating initial capacity and Load Factor
-
-
-
Iterating over this set requires time proportional to the sum of set size + "capacity" of HashMap, Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important
Not synchronized
If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externall. Example Collections.synchronizedSet(new HashSet())
The iterator returned by this class's iterator are fail-fast (if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator throws a ConcurrentModificationException)
-
-
SortedSet
TreeSet
Implementation based on a TreeMap. The elements are ordered using their natural order or passing Comparator during creation.
-
-
-
-