java collections concept

15
Collection Framework concept in Java Kumar Gaurav [email protected]

Upload: kumar-gaurav

Post on 12-Apr-2017

339 views

Category:

Technology


2 download

TRANSCRIPT

Collection Framework concept in Java

Kumar [email protected]

Need of collection framework?

Due to limitation of arrays Arrays store homogenous data types only and fixed size Collections allowed to store heterogeneous data types with

growable size Collection Framework is set of several classes and interfaces

that helps to achieve this target

9 key interfaces of collection framework

Collection List Set SortedSet NavigableSet Queue Map SortedMap NavigbleMap

1- Collection

Whenever we would like to represent a group of objects as a single entity, we use Collection for the same

It is also known as root interface of collections framework but not completely

There is no concrete class that implements collection interface directly

It defines most common methods which are applicable on any collection object -

2- List

List is child interface of Collection Representing a group of object as a single entity with the

condition that - Duplicates are allowed Insertion order is preserved

Duplicates identified by index Preserving insertion order by index Index has very important role

3- Set

It is child interface of Collection Representing a group of object as a single entity with the

condition that - Duplicates are not allowed Insertion order is not preserved

4- SortedSet

It is child interface of Set Representing a group of object as a single entity with the

condition that - Duplicates are not allowed Insertion order is not preserved Objects should be stored in some sorted order

5- NavigableSet

It is child interface of SoretdSet It defines several methods for navigation purpose TreeSet is the implementation class

6- Queue

It is the child interface of Collection If we want to represent a group of objects prior to processing

then we should go for Queue For e.g. suppose we have to send email to 100 email id’s so we have

to store it somewhere and the emails will be delivered in the same order they were saved

Wait a min before next…

All discussed 6 interfaces Collection, List, Set, SoretdSet, NavigableSet, Queue meant for representing a group of individual object as a single entity

If we want a represent group of objects as key-value pairs then we should go for Map interface

7- Map

Map interface is not the child of Collection interface If we want to represent a group of objects as key-value pairs then

should go for Map Both key and value are objects Duplicate key is not allowed, value can be duplicate

8- SortedMap

It is the child interface of Map If we want to represent a group of key value pairs as per some

sorting order then SortedMap is used

9- NavigableMap

It is the child interface of SoretdMap It defines several utility methods for navigation purpose TrreeMap is the implementation class

References

Durgasoft java tutorial http://durgasoft.com/ Oracle

https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html

Thank you!