Collections Interview Questions

Collections Interview Questions.

  1. What is collection in java ?Difference between collection, Collections and Collection in java?
  2. Collection hierarchy in Java.
  3. Collections class in Java.
  4. Difference between Arrays and Collections framework in java. Benefits of collections over arrays in java.
  5. ArrayList in Java.
  6. Different ways to iterate ArrayList in java.
  7. Important methods and constructors of ArrayList with an example.
  8. How to Synchronized ArrayList in java?
  9. How to convert ArrayList into Set?
  10. How to convert ArrayList to array and array to ArrayList in Java?
  11. How to make List, Set and Map Read Only in Java?
  12. How to avoid duplicate elements in ArrayList?
  13. Adding Custom type class object in ArrayList?
  14. What will happen if we define List as final? Can we add more elements?
  15. ArrayList vs Vector in java.
  16. What is the difference between ArrayList and LinkedList in java?
  17. What is the difference between List and Set in java?
  18. What is the difference between HashSet and TreeSet in java?
  19. What is the difference between HashSet and HashMap in java?
  20. What is the difference between Enumeration and Iteration in java?
  21. What is the difference between Iterator and ListIterator?
  22. What is the difference between Comparable and Comparator in java?
  23. What is the difference between HashMap and Hashtable in java?
  24. What is Comparable in java? Write a program to sort on basis of id using Comparable?
  25. What is Comparator in java? Write a program to sort using Comparator?
  26. Vector in Java
  27. LinkedList in Java
  28. HashSet in Java
  29. LinkedHashSet in Java
  30. TreeSet in Java
  31. HashMap in java
  32. Hashtable in java
  33. LinkedHashMap in Java
  34. TreeMap in java
  35. How to create custom HashSet in java
  36. Sort HashMap by key in java
  37. How to create a custom linked list in java
  38. Sort HashMap by value in java
  39. Performance in case of ArrayList and Vector.
  40. How to allow duplicate elements in Set
  41. How to define custom ArrayList in java
  42. Sort HashMap by value in java
  43. How to create a custom linked list in java
  44. Sort HashMap by key in java
  45. How to create custom HashSet in Java.
  46. Performance in case of HashMap and Hashtable.
  47. User defined class as key in HashMap in Java.
  48. How HashSet works internally in java
  49. How get method of ArrayList work internally in java.
  50. Fail fast and fail safe example in java.

 

What is a collection in java ? Difference between collection, Collections, and Collection in java? 

A collection is an object that groups one or more than one element into a single unit. Collection framework provides interfaces and classes to store, retrieve and manipulate the data.
A collection framework contains interfaces, implementations, and algorithms.
interfaces -Interfaces allow collections to be manipulated independently of the details of their representation
implementations- These are reusable data structures.
algorithms – These are the methods that perform a different operation such as searching and sorting, on objects that implement collection interfaces.
Algorithms are reusable functionality.

Use of collection:-

  1. We can add objects to the collection.
  2. We can remove objects from the collection.
  3. We can find out an object or group of objects from the collection.
  4. We can iterate through the collection.

Don’t get confuse :-
Don’t get confused about collection, Collection, Collections. Let’s see the difference between them.
collection:-it represents any of data structure in which objects are stored and iterated over.
Collection:-This is an interface available in java.util package.
Collections:- This is a class available in java.util package. It has a static utility method for use with collections.

 

 

Top