Java Interview Questions and Answers on Collection - PLM Developer

Collections are one of the widely used concepts in java. As a developer, I use java collection concepts while writing the code every day. Collections play a vital role in application development. The primary use of java collections is to hold and process the data and perform many operations like searching and sorting. So, Collection is an essential topic for any java coding interview. This post is dedicated to frequently asked java collection interview questions and answers.


Key Points:

  • List maintains insertion order & allows duplicates.
  • Set removes the duplicates & doesn't maintain any order.
  • Map maintains the data in key-value pairs so that we can get any value using its key. This feature makes retrieving (search) element O(1) time.

Q. What is the collection framework in java?

The collection framework is a combination of classes and interfaces used to store and maintain the data in objects. Collection framework offers various classes like ArrayList, Vector, HashSet, Stack, and interfaces like List, Set, Queue, etc.

Q. What is the difference between Array and Collection?

An array stores homogenous elements.

Collection stores heterogeneous elements.

Arrays are fixed in size.

The Collection grows dynamically when the size of the collection object is full.

Arrays don't provide any methods to do operations on data.

The Collection provides readymade methods to do operations on data like searching and sorting.

Q. what is the difference between List and Set?

The list is an ordered collection of elements. It preserves the insertion order and allows duplicate elements.

Set is a collection that doesn't preserve the insertion order and doesn't allow duplicates.

Q. What is the difference between ArrayList and Vector?

  • ArrayList is not synchronized.
  • Vector is synchronized
  • ArrayList is not thread-safe so, multiple threads can operate concurrently.
  • Vector is thread-safe so, multiple threads can't operate concurrently.
  • ArrayList increases its size by 50% when the list is full.
  • Vector doubles its size when it is full.
  • ArrayList is not a legacy class.
  • Vector is a legacy class.

Q. What is the difference between HashMap and TreeMap?

HashMap doesn't follow any order, but TreeMap stores the elements in ascending order.

HashMap can have a null key with multiple null values, whereas TreeMap cannot have the null key but can have multiple null values.

Q. What is the difference between HashSet and TreeSet?

Elements in HashSet are not ordered, but TreeSet stores the elements in ascending order by default.


HashSet gives better performance while doing operations like search, insert and delete takes constant time on average, whereas TreeSet is slower than HashSet.


See Also:

πŸ‘‰Java Interview Questions & Answers 1

πŸ‘‰Java Interview Questions & Answers 2

πŸ‘‰Java Interview Questions & Answers 3


Post a Comment


  1. You can find Netent, Microgaming, Play'n GO, Betsoft, and rather more at ICE Casino. Live on line casino video games out there, so might be} hard to know where begin out|to begin}. Cosmo has a huge variety 솔 카지노 of 2000 video games, principally slot video games, obtainable in its library. The most spectacular a part of} this feature is the occasional updates and addition of recent video games to the site, similar to pokies for its kiwi gamblers.