Questions
Questions
A:
Q: How do you decide when to use ArrayList and When to use LinkedList?
A: In an ArrayList direct access to any element based on its index is very fast ,where as in linked list
the access to elements by index is comparatively slow. In array list Insertion and deletion are very slow
where as in LinkedList it is very fast. So I would use ArrayList where I need fast retrieval by index and
I would use LinkedList when I need to do many insertion and deletion.
Q: What is an Iterator?
A: Iterator is an Interface whose implementations are returned by the iterator() method in the collection
classes, Iterators are used for iterating through the elements in a collection, It also allows us to remove
elements during the iteration.
Q: What is a Set?
A: A set is a collection of Objects in which duplicates are not allowed, it models the mathematical set.
Q: What is a HashSet?
A: A HashSet is an Implementation of the SetInterface which internally uses a Hash Table like
datastructure(actually elements are stored as keys in a HashMap) structure. It does not guarantee that
the insersion order will be maintained and order may not remain constant with time.
Q: What is a TreeSet?
A: TreeSet is a Set implementation that keeps the elements in sorted order. The elements are sorted
according to the natural order of elements or by the comparator provided at creation time.
Q: What is EnumMap?
A: A specialized Map implementation for use with enum type keys. All of the keys in an enum map
must come from a single enum type that is specified, explicitly or implicitly, when the map is created.
Q:What is a HashMap?
A: HashMap is an implementation of HashMap that is based on the hash table data structure.
Q:What is a TreeMap?
A: TreeMap actually implements the SortedMap interface which extends the Map interface. In a
TreeMap the data will be sorted in ascending order of keys according to the natural order for the key's
class, or by the comparator provided at creation time. TreeMap is based on the Red-Black tree data
structure.