List :
ArrayList and LinkedList
List is a ordered collection.
Set :
HashSet and TreeSet
- A collection that CANNOT contain duplicate elements.
- Used to represent cards in a poker hand or processes running on a machine
- HashSet is much faster but no ordering guarantees. This is mostly used.
- TreeSet is in order iteration . What you entered will be in same sequence while iteration FIFO
- Default initial capacity is 101. Should set it twice the size that you expect the Set to grow.
Set s = new HashSet(17); Here intial capacity is set to 17 - Load factor is the tuning parameter. Default is (.75) when the number of entries exceeds the product of the load factor and the current capacity the capacity is doubled. Higher value decrease the space overhead, but increase the time it takes to look up an entry.
Map :
HashMap and TreeMap
Synchronized Collections
- HashTable and Vector are fully synchronized Classes in the collections framework are not synchronized by default.
- Wrapper classes add functionality to the standard Collection (interface) implementation.
- Factory method defined in the Collections class(not to be confused with the Collection interface).
public static Collection synchronizedCollection(Collection c);
public static Set synchronizedSet(Set s);
public static List synchronizedList(List list);
public static Map synchronizedMap(Map m);
public static SortedSet synchronizedSortedSet(SortedSet s);
public static SortedMap synchronizedSortedMap(SortedMap m);
Collection c = Collections.synchronizedCollection(myCollection);
Synchronized(c){
Iterator i = c.iterator(); // it should be inside synchronized block
While(i.hasNext()){
System.out.println(i.next());
}
Algorithms
- sort and binarySearch available in Collections class as static method.
public static int binarySearch(List list, Object key);
public static int binarySearch(List list, Object key,Comparator c);
public static void sort(List list);
public static void sort(List list, Comparator c);
(Read more on this link. This blog is summary sun java)
No comments:
Post a Comment