Sei sulla pagina 1di 4

Comparison between Arrays and Collections Arrays Fixed in size Collections Growable in nature

With respect to memory Arrays are not With respect to memory Collections are preferable recommended to use Arrays show very good performance Can hold only homogeneous data elements No undertaking data structure and ready made support is not available Arrays can hold both primitives and objects Collections show very poor performance Can hold both homogeneous and heterogeneous elements Underlaying data structure is available and for any requirement ready made method support is available. Collections can hold only object, but not primitives.

Collection VS Collections:: Collection :: is an interface for representing a group of objects as single entity. Collections :: is an utility class available in java.util package for defining several utility methods for collection objects. ---------**************************************** Difference between Array List and Vector Array List No method is synchronized All objects is not thread safe. Vector All methods are synchronized Vector object is thread safe

Performance is high at a more threads Performance is low only on thread allow

Comparison table for enumeration, Iterator, List Iterator. Property It is Legacy? Applicable for Movement How to get? Accessibility Methods Yes Enumeration No Iterator No Only list implement classes Bi-dirction By using list iterator Read / Remove / Replace / Add Hasnext(), hasprevious() List Iterator

Only Legacy classes Any collection implemented class Single directional (forward) Single directional (forward)

By using elements() By using iterator() Only read access Has move elements Read / Remove Hasnext(), next(), remove()

Hashset and Linked Hashset Hashset Underlying data structure is Hashtable Insertion order is not reversed Introduced in 1.2 version Linked Hashset Underlying data structure is Linked List + Hashtable Insertion order is preserved Introduced in 1.4 version

Comparison between Comparable and Comparator Comparable Available in java.lang package Comparator Available in java.util package

Contains any one method compareTo() Contains 2 methods compare(), equals()

Comparable

Comparator

String class and all wrapper classes all No predefined class implemented ready implemented comparable comparator interface It is a marker interface It is not a marker interface

Property Data Structure Insertion Order Sorting order Duplicate Objects Heterogeneous objects Null Insertion

Hash Set Hashtable Not presented

Linked Hash Set Hashtable + Linked List Presented

Tree Set Balanced Preserved

Not allowed

Possible

Possible

For the empty Trees as the first element it is possible 1.4 1.2

Version

1.2

Difference between HashMap and Hashtable Hashmap No method is synchronized This object is not thread safe Performance is high Null is allowed for both key and value Hashtable All methods are sycronized This object is thread safe Performance is low Null is not allowed for keys and values,

Hashmap

Hashtable other wise null pointer exception.

Version 1.2

Version 1.0

Difference between Hahmap and Linked Hashmap Hahmap Underlying data structure is hashtable Insertion order is not preserved 1.2 version Linked Hashmap Underlying data structure is hashtable + linked list Insertion order is preserved 1.4 version

-------********************----------------------****************************---------------

Potrebbero piacerti anche