Fresher Java Interview Questions in Auromine Solutions – Part – III

This blog explains about  Fresher Java Interview Questions in Auromine Solutions –

Part – III . Some of them are discussed below : 

 We have already discussed some questions in the previous blogs. Let us see few more questions here .   


Fresher Java Interview Questions in Auromine Solutions – Part – I  & II

 1. What is difference  between set and list ?

                                            List Vs Set

1) List is an ordered collection it maintains the insertion order, which means upon displaying the list content it will display the elements in the same order in which they got inserted into the list.

Set is an unordered collection, it doesn’t maintain any order. There are few implementations of Set which maintains the order such as LinkedHashSet (It maintains the elements in insertion order).

2) List allows duplicates while Set doesn’t allow duplicate elements.

All the elements of a Set should be unique if you try to insert the duplicate element in Set it would replace the existing value.


2. What is different between list and Map ?

                                   List Vs Set Vs Map

1) Duplicity: List allows duplicate elements. Any number of duplicate elements can be inserted into the list without affecting the same existing values and their indexes.

Set doesn’t allow duplicates. Set and all of the classes which implements Set interface should have unique elements.

Map stored the elements as key & value pair. Map doesn’t allow duplicate keys while it allows duplicate values.

2) Null values: List allows any number of null values. Set allows single null value at most.

Map can have single null key at most and any number of null values.

3) Order: List and all of its implementation classes maintains the insertion order.

Set doesn’t maintain any order; still few of its classes sort the elements in an order such as LinkedHashSet maintains the elements in insertion order.

Similar to Set Map also doesn’t stores the elements in an order, however few of its classes does the same.

For e.g. TreeMap sorts the map in the ascending order of keys and LinkedHashMap sorts the elements in the insertion order, the order in which the elements got added to the LinkedHashMap.


3. What is different between ArrayList and Array ? 

Array is used to hold multiple values of same type. An array may hold –

  • Multiple primitive values of same type , or
  • Multiple object references of same type.

Types of array

  • One-dimensional array(1-D), it’s a single array that holds multiple values of the same type. For more on Array , you may read, Array in Java-
  • Two-dimensional array(2-D), it’s an array containing multiple arrays within it, where all of these multiple array holding values of a same type. For more on2D array and how they are declared, initialized and created, you may read Two Dimensional Array in Java

ArrayList :

Just like a standard array, ArrayList is also used to store similar elements. In the case of a standard array, we must declare its size before we use it and once its size is declared, it’s fixed.

While ArrayList is like a dynamic array i.e. we don’t need to declare its size, it grows as we add elements to it and it shrinks as you remove elements from it, during the runtime of the program.