SortedSet

1) It is child interface of Set.
2) If we want to represent a group of “unique objects” according to some sorting order then we should go for SortedSet interface.
3) That sorting order can be either default natural sorting (or) customized sorting order.
• SortedSet interface define the following 6 specific methods.
Continue reading SortedSet

The 3 cursors of java

• If we want to get objects one by one from the collection then we should go for cursor. There are 3 types of cursors available in java. They are:
1) Enumeration
2) Iterator
3) ListIterator

Continue reading The 3 cursors of java

LinkedHashSet

1) It is the child class of HashSet.
2) LinkedHashSet is exactly same as HashSet except the following differences.
linkedhashset
Continue reading LinkedHashSet

HashSet

1) The underlying data structure is Hashtable.
2) Insertion order is not preserved and it is based on hash code of the objects.
3) Duplicate objects are not allowed.
4) If we are trying to insert duplicate objects we won’t get compile time error and runtime error add() method simply returns false.
5) Heterogeneous objects are allowed.
6) Null insertion is possible.
7) Implements Serializable and Cloneable interfaces but not RandomAccess.
Continue reading HashSet

Set interface

1) It is the child interface of Collection.
2) If we want to represent a group of individual objects where duplicates are not allow and insertion order is not preserved then we should go for Set interface.
Diagram:
setinterface

• Set interface does not contain any new method we have to use only Collection interface methods.

LinkedList

1) The underlying data structure is double LinkedList
2) If our frequent operation is insertion (or) deletion in the middle then LinkedList is the best choice.
3) If our frequent operation is retrieval operation then LinkedList is worst choice.
4) Duplicate objects are allowed.
5) Insertion order is preserved.
6) Heterogeneous objects are allowed.
7) Null insertion is possible.
8) Implements Serializable and Cloneable interfaces but not RandomAccess.
Continue reading LinkedList

Vector

1) The underlying data structure is resizable array (or) growable array.
2) Duplicate objects are allowed.
3) Insertion order is preserved.
4) Heterogeneous objects are allowed.
5) Null insertion is possible.
6) Implements Serializable,Cloneable and RandomAccess interfaces.
Continue reading Vector

Stack

1) It is the child class of Vector.
2) Whenever last in first out order required then we should go for Stack.
Constructor:
• It contains only one constructor.
Stack s = new Stack();
Continue reading Stack

Getting synchronized version of ArrayList object

• Collections class defines the following method to return synchronized version of List.
Public static List synchronizedList(list l);
Example:
synchro
Continue reading Getting synchronized version of ArrayList object

Differences between ArrayList and Vector?

ArrayList
1) In ArrayList ,no any method is synchronized
2) At a time multiple Threads are allow to operate onArrayList object and hence ArrayList object is not Thread safe.
3) Relatively performance is high because Threads are not required to wait.
4) It is non legacy and introduced in 1.2v
Continue reading Differences between ArrayList and Vector?