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

Java collections concept

Apr 12, 2017

Download

Technology

Kumar Gaurav
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Java collections concept

Collection Framework concept in Java

Kumar [email protected]

Page 2: Java collections concept

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

Page 3: Java collections concept

9 key interfaces of collection framework

Collection List Set SortedSet NavigableSet Queue Map SortedMap NavigbleMap

Page 4: Java collections concept

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 -

Page 5: Java collections concept

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

Page 6: Java collections concept

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

Page 7: Java collections concept

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

Page 8: Java collections concept

5- NavigableSet

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

Page 9: Java collections concept

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

Page 10: Java collections concept

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

Page 11: Java collections concept

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

Page 12: Java collections concept

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

Page 13: Java collections concept

9- NavigableMap

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

Page 14: Java collections concept

References

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

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

Page 15: Java collections concept

Thank you!