Java Collections Interview Questions

LearnNewTech
2 min readApr 8, 2022

What are the basic interfaces of Java Collections Framework ?

Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects. The most basic interfaces that reside in the Java Collections Framework are:

Collection->which represents a group of objects known as its elements

Set ->which is a collection that cannot contain duplicate elements.

List ->which is an ordered collection and can contain duplicate elements. • Map ->which is an object that maps keys to values and cannot contain duplicate keys

2.Why Collection doesn’t extend Cloneable and Serializable interfaces ?

The Collection interface specifies groups of objects known as elements. Each concrete implementation of a Collection can choose its own way of how to maintain and order its elements. Some collections allow duplicate keys, while some other collections don’t. The semantics and the implications of either cloning or serialization come into play when dealing with actual implementations. Thus, the concrete implementations of collections should decide how they can be cloned or serialized.

3.What is an Iterator ?

The Iterator interface provides a number of methods that are able to iterate over any Collection. Each Java Collection contains the iterator method that returns an Iterator instance. Iterators are capable of removing elements from the underlying collection during the iteration.

4.What is ArrayList in Java?

ArrayList is the implementation of List Interface where the elements can be dynamically added or removed from the list. ArrayList in the Collection framework provides positional access and insertion of elements. It is an ordered collection that permits duplicate values. The size of an ArrayList can be increased dynamically if the number of elements is more than the initial size.

Syntax:ArrayList object = new ArrayList ();

5. How would you convert an ArrayList to Array and an Array to ArrayList?

Syntax:

Arrays.asList(item)

Whereas an ArrayList can be converted into an Array using the toArray() method of the ArrayList class.

Syntax:

List_object.toArray(new String[List_object.size()])

--

--