Collection Framework Interview Questions
Collection Framework Interview Questions for Freshers
Collection Framework Interview Questions
Main advantage of Collection Framework ?
Collections are grow-able in nature and hence based on our requirement we can increase or decrease the size and it store homogeneous data type. The basic aim of collection framework is to improve the performance of java based application.
Difference between Array and Collection
| Array | Collection |
1 | Arrays are fixed in size and hence once we created an array we are not allowed to increase or decrease the size based on our requirement. | Collections are grow-able in nature and hence based on our requirement we can increase or decrease the size. |
2 | Arrays can hold both primitives as well as objects. | Collections can hold only objects but not primitive. |
3 | Performance point of view arrays faster than collection | Performance point of view collections are slower than array |
4 | Arrays can hold only homogeneous elements. | Collections can hold both homogeneous and heterogeneous elements. |
5 | Memory point of view arrays are not recommended to use. | Memory point of view collections are recommended to use. |
6 | For any requirement, there is no ready method available. | For every requirement ready made method support is available. |
Note: Above difference is same for difference between Array and any Collection object (like Vector, ArrayList, LinkedList).
Difference between Iterator and ListIterator
| Iterator | ListIterator |
1 | Iterator is one of the super Interface for ListIterator | ListIterator is one of sub-Interface of Iterator |
2 | This Interface is allow to retrieve the element only in forward direction | This Interface is allow to retrieve the element in both direction either in forward and backward direction. |
How many Technique to retrieve elements from Collection object ?
Java support following technique to retrieve the elements from any collection object.
- foreach loop
- Iterator interface
- ListIterator interface
- Enumeration interface
Difference Between Vector and ArrayList ?
| Vector | ArrayList |
1 | Vector is legacy Collection Framework (old class). | ArrayList is new Collection Framework. |
2 | Vector is Synchronized by default. | ArrayList is not Synchronized. |
3 | For retrieving elements from Vector class can be use foreach loop, Iterator, ListIterator and Enumaration. | For retrieving elements from ArrayList class can be use foreach loop, Iterator and ListIterator. |
Difference between HashMap and HashTable ?
| HashMap | HashTable |
1 | HashMap is a new class in java API. | HashTable is a legacy class in java API. |
2 | HashMap is not Synchronized. | HashTable is Synchronized. |
3 | HashMap allows maximum one null key and multiple null value. | HashTable does not allows any null key and null values. |
Difference between HashMap and TreeMap
| HashMap | TreeMap |
1 | HashMap class object organizes the data in the form of key, value pair by following hasing mechanism. | TreeMap class object organized the data in the form of key, value pair by following binary tree concept. |
2 | HashMap store data in undermined form. | TreeMap store data in sorted order. |
3 | In HashMap the operation like insertion, deletion and modification takes less time. | In TreeMap the operation like insertion, deletion and modification takes more time. |
3 | Elements retrieving time of HashMap is more. | Elements retrieving time of TreeMap is less. |
Difference between HashSet and TreeSet
| HashSet | TreeSet |
1 | HashSet class object organizes the data in the form HashTable by following Hashing mechanism. | TreeSet class object organized the data by following binary tree concept. |
2 | HashSet display data in undermined form. | TreeSet display data in sorted order. |
3 | In HashSet the operation like insertion, deletion and modification takes more time. | In TreeSet the operation like insertion, deletion and modification takes less time. |
3 | Elements retrieving time of HashSet is more. | Elements retrieving time of TreeSet is less. |
What is Properties Files ?
A property file is one type of the file which organizing the date in the form of (key, value) pair. A property file is a text file which is to be created in any editors like-notepad, Editpuls and etc. Property file should be saved on same file name with on extension .prop or .rbf.
Why Legacy Collection Framework are not use for web based applications. ?
Legacy Collection Framework are Synchronized because of this we can not use Legacy Collection Framework for web based applications.
Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet