- Collection is an object representing a group of objects.
- Collection framework contains a set of classes and interfaces which are used for representing and manipulating collections.
- Collection interface is the root interface from which the interfaces List, Set,Queue are extended.
- List interface is an ordered collection in which duplicate elements are also allowed.
- Elements are stored in a sequential way and hence its elements can be accessed using the index value.
- Set is an unordered collection. It does not maintain any order while storing the elements. It does not allow duplicate elements.
Thus if one requires to store a group of unique elements, set can be used.
- Map is an interface which maps keys to values in which each key has to be unique.
Retrieving elements from collection:
- Iterator interface is used to iterate over a collection object and retrieve the elements one after the other.
- ListIterator is similar to Iterator interface except that the elements of the collection can be retrieved from both forward and backward direction.
- Enumeration interface is similar to Iterator interface except that it cannot remove elements and can only iterate over the collection object.
Iterating using enhanced for loop:
- Enhanced for loop can also be used to iterate over the collection object.
|List<String> places= new LinkedList<String>();
for(String place: places)
1. Online Compilers - Compile & Run your C/C++ programs:
2. Ask your questions or clarify your/others doubts from,