Some Important type of Collections:

1.Sorted Set: Elements of this set are ordered by their natural ordering or by a Comparator.

2. Tree Set: Same as above.

3. Priority Queue: Same as above.

4.List: Has ordering by index.

Tree Set and Prority Queue are non-synchronized.

Nothing specific is said for Sorted set in terms of synchronization in the api.

So what exactly is this over hyped “Natural Ordering”??

Natural ordering is the ordering we achieve by implementing the Comparable interface, i.e., the compareTo() method.

If the compareTo() is overridden in such a way that compareTo() returns a fixed positive integer.Then on retrieving the added elements from that “comparable” collection, they’ll be displayed in the order in which they were added.

Generics:

Q.What is the equivalence of the statement List list??

A.List list is equivalent to List<?> list;

List list is equivalent to List<? extends Object> list.

List list is definitely NOT equivalent to List<Object> list.

Advertisements