Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Sunday

Java Collection Interview questions and answers for experienced and freshers

Java Collection Interview questions and answers for experienced and freshers

Java Collection Framework is a big and vast topic each and every software developer has to understand and needs to apply in different areas. These are the some of the normal interview questions asked in Java Collections Interview questions.

  1. How HashMap works in java? :-  Normally candidature will answer that it uses key and value pair to put and retrieve objects. But do you know whats the technique underlying. Whwn you put a object using Map.put(key,vale) it calls the keys hashcode function in which a hashcode is generated and it finds a bucket location to store the object. Normally HashMap uses Map.Entry for this operation. When we call the get(key) the same hashcode is generated to retrive the object back from the bucket.
  2. What is difference between fail-fast and fail-safe Iterators? :-  Fail-Fast is thing in which when you are iterating over a list, if there occurs any modification in the list like adding or removal of object it throws exception. On the other hand Fail-Safe allows addition and removal of objects while traversing over the List or Set etc...
  3. What is difference between Iterator and Enumeration? Both are used to traverse though the collection. But Iterator is faster than Enumerator. Enumeration is thread safe. It has a remove() functionality other than Iterator.
  4. Difference between HashMap and Hashtable? :- HashMap is not synchronized while Hashtable is not or hashmap is faster than hash table.
  5. What is difference between Set and List in Java? : - Its a normal question and the answer is List does allow duplicates and Set does. List maintains a sorted order while Set not.
  6. How do you Sort objects on collection? :- Collections.sort() is used to sort collection objects. but it can use Comparable and Comparator interface.
  7. What is difference between Vector and ArrayList? :- Vector is synchronized and slow. but ArrayList is not synhronized and fast.
  8. What is difference between HashMap and HashSet? :- HashMap allows duplicate values while HashSet allows unique values.

No comments:

Post a Comment