Collection Framework Interview Questions

Collection framework is very importatnt for interview. You will face questions from collection framework in almost every java interview This page contains the most important collection framework interview questinos and answers. For more questions on various topics of core java navigate thorough the links privided in below table or at end of the page.

Overview : Most Imp Questions Java Basic Interview Questions
OOPS Concepts Interview Questions Exception Handling Questions
MultiThreading & Concurrency API Java API : String, File I/O
Collection Framework Questions Advanced Questions

ArrayList and LinkedList both implement List interface and their methods are almost same, still there are some differences as explained below:
ArrayList LinkedList
Search is very fast in ArrayList as it maintain index based system. O(1) Search is slow, as it has to traverse through all elements. O(n)
Modification (insert or delete) to ArrayList is slow. Modification to LinkedList is very fast.
Memory consumption is low. Memory consumption is high as it maintains data and 2 pointers for neighbor nodes.
Use it when the collection has less moodification and more retrival. Use it when you collection is expected to undergo multiple modification (especially in between elements).
List Set
List can contain duplicates elements. Set don't contain duplicate elements.
All List implementations store elements in insertion order. Different implementation has different order of elements. HashMap elements are not ordered.
HashTable HashMap
HashTable is a legacy class. HashMap is part of java collection frameowrk.
All methods are synchronized. Its not synchronized.
HashTable does not allow null key and value. HashMap allow one null key and multiple null value.
By using Collections.synchronizedList(), synchorinizedSet() or synchronizedMap() method.
Yes, you can modify it but only when you are navigating using iterator and by using only Iterator or ListIterator class methods.
If you are navigating/iterating using for loop, or if you try to modify by ArrayList class methods it give ConcurrentModificationException.
Either through keySet() or through entrySet();
ConcurrentMap is subinterface of Map and has ability to handle concurrent access (get and put ) to it. ConcurrnetMap is an interface and ConcurrentHashMap is its implementing class.
ConcurrentHashMap is a bit similar to HashTable but it handles concurrency much better. ConcurrentHashMap does not lock the map while you are reading from it. Also while you are writing to it, it only locks a part of the map that is being written to, internally.
java.util.concurrent.ConcurrentNavigableMap is a subclass of java.util.NavigableMap.

<< Previous Page : 1 2 3 4 5 6 7 8 Next >>