Nine Key Interfaces of Collection Frame Work
Ans:-
- If you want to represent a group of Individual object as a single entity then we should go for Collection.
- Collection interface defines the most common method whic are applicable for any Collection Object.
- In general Collection interface is considered as root interface of colloetion frame work.
Important Methods of Collection Interface
- boolean add(Object o)
- boolean addAll(Collection c)
- boolean remove( Object O)
- boolean removeAll(Collection c)
- boolean retainAll(Collection c)
- void clear()
- boolean contains(Object o)
- boolean containsAll(Collection c)
- boolean isEmpty()
- int size()
- object[] toArray()
- Iterator iterator()
Ques2:- What is List interface?
Ans:-
- List is a child interface of collection.
- If you want to represent a group of Individual object as a single entity where duplicates are allowed and insertion order must be preserved then we should go for List.
Ques3:- What is Set?
Ans:-
- Set is a child interface of Collection
- if we want to represent a group of individual object as a single entity where duplicates are not allowed and insertion order not preserved then we should go for Set interface.
Ques4:- What is SortedSet interface?
Ans:-
- it is the child interface of Set.
- if we want to represent a group of individual object as a single entity where duplicates are not allowed and all object should be inserted according to some sorting order then we should go for SortedSet.
Ques5:- What is NavigableSet?.
Ans:-
- it is a child interface of SortedSet.
- it contains several methods for navigation purpose.
Ques6:- What is PriorityQueue?
Ans:-
- it is child interface of Collection.
- if we want to represent a group of individual object prior to processing then we should go for Queue. Usually Queue follow first-in-firstout order but based on our requirement we can implement our own priority order also before sending a mail all mail id we have to store in some data structure, in which order we have to added mail-ids in the same order only mail should be delivered for this requirement Queue is best choice.
Ques7:- What is Map?
Ans:-
- Map is not child interface of Collection.
- if we want to represent a group of individual object key value pairs then we should go for Map.
SNO. | RollNo | Name |
1 | 101 | Ramesh |
2. | 102 | Ganesh |
3. | 103 | Manu |
4. | 104 | Lalita |
NOTE:- Both Key and value are objects duplicates key are not allowed but value can be duplicated.
Ques:8- What is SortedMap?
Ans:-
- it is the child interface of map.
- if we want to represent a group of key value pairs according to some sorting order of keys then we should go for SortedMap.
Ques:9- What is NavigableMap?
Ans:-
- it is the child interface of SortedMap.
- it defines several utility methods for navigation purpose.
Ques:10- What is ArrayList?
Ans:-
- Underlined data structure resizable Array or Growable Array.
- Duplicates are allowed.
- insertion order preserved.
- Heterogenous objects are allowed[except Tree Set and Tree Map everywhere hetrogenous objects are allowed].
- Null insertion is possible.
Que:11- What is Collection frame work in java?
Ans:-
- Collection frame is combination of classes and interfaces which is used to store the data in the form of object and also manipulate the data in the form of object it provides various classes and interfaces such as ArrayList, Hashtable, vector, hashset etc. and interfaces such as List, Set, Queue, Map etc.
Ques:12- What is the difference between Array ArrayList?
Ans:-
SNO. | Array | ArrayList |
1 | 1. The array is of fixed size, means we cannot increase or decrease according to our requirement. |
1.ArrayList is not of fixed size. we can change the size dynamically. |
2. | 2.Arrays are of the static type. |
2.ArrayList is of dynamic type. |
3. | 3.Array can store primitve datatypee as well as objects. |
3.ArrayList can not store the primitive data types it can only store the objects. |
4. | 4.Array donot provide any bulit-in method to develop the program. we develop our own logic. |
4.ArrayList provide lot of built-in mehtod with the help of these built-in we progrm is easy to develop.ArrayList store only objects object can be anything. double, float string, character,boolean etc |
5. | 5.Array is synchronized. |
5.ArrayList is non synchronized. |
Ques:13- What is the difference between Array and Collections.?
Ans:-
SNO. | Array | Collections |
1 | 1.Arrays are fixed size. |
1.Collection are growable in nature.I.e based on our requirement.we can increase or decrease the size. |
2. | 2.Wrt memory arrays are not recommended to use. |
2. Wrt to memory collections are recommended to use. |
3. | 3.Wrt performance arrays are recommended to use. |
3.Wrt performance Collections are not recommended to use. |
4. | 4. Array can hold only homogenous datatype elements. |
4.Collections can hold both homogenous and hetrogenous datatype elements. |
5. | 5.There is no underlying data structure for arrays and hence readymade method support is not available. |
5.Every Collections class is implemented based on some standard data structure hence readymade method support is available for every requirement. |
6. | 6.Array can hold both primitives and object types. |
6.Collections can hold only objects but not primitives. |
Ques:14- Why do we require Collections.?
Ans:- To overcome the above limitations of Arrays we should go for Collections.➤Collections are growbable in nature that is based on our requirement and we can also increase or decrease the size.
➤Collections can hold both homogeneous and heterogeneous elements.
➤Every Collections class is Implemented based on some standard data structure. Hence readymade support is available for every requirement. Being a programmer we have to use this method and we are not responsible to provide implementation.