0% found this document useful (0 votes)
22 views

Defined Manner.: Collections Are Nothing But Group of Objects Stored in Well

Collections in Java provide a unified framework for storing and manipulating groups of objects. The key classes include List for ordered collections allowing duplicates, Set for unordered collections with unique elements, Queue for first-in first-out collections, and Map for storing key-value pairs with unique keys. The Collection framework handles different types of collections in a consistent way and allows operations like adding and removing objects without reimplementing functionality.

Uploaded by

Ganesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Defined Manner.: Collections Are Nothing But Group of Objects Stored in Well

Collections in Java provide a unified framework for storing and manipulating groups of objects. The key classes include List for ordered collections allowing duplicates, Set for unordered collections with unique elements, Queue for first-in first-out collections, and Map for storing key-value pairs with unique keys. The Collection framework handles different types of collections in a consistent way and allows operations like adding and removing objects without reimplementing functionality.

Uploaded by

Ganesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Collections 

are nothing but group of objects stored in well


defined manner.
Although, there were classes
like Dictionary, Vector, Stack and Properties which handle group of objects
better than the arrays. But, each of them handle the objects differently. The
way you use Dictionary class is totally different from the way you
use Stack class and the way you use Vector class is different from the way you
use Properties class. Hence, there needed a central and unifying
theme to handle the group of objects. The collection framework is the answer
to that.

What is Collection Framework In Java?

Collection Framework in java is a centralized and unified theme to store and


manipulate the group of objects. Java Collection Framework provides some
pre-defined classes and interfaces to handle the group of objects. Using
collection framework, you can store the objects as a list or as a set or as
a queue or as a map and perform operations like adding an object or removing
an object or sorting the objects without much hard work.
--------------- ----------------- ------------------------ ----------------------------- ------------
List Set Queue Map
Ordered, Unordered, It is a DS which Key value pair,
duplicates Unique is based on FIFO has unique keys

Stack – LIFO manner


-------------- ------------------------------- ---------------------------- --------------------- ---------

HashSet LinkedHashSet Treeset


Non-duplicate Non-duplicate Non-duplicate
Un ordered Ordered Sorted
Internally Hashmap LinkedHashSet extends Internally uses Treemap
HashSet that means it is
a HashMap without
duplicates. But the
difference here with
HashSet is that
LinkedHashSet is
ordered. It uses a
Doubly Linked List that
runs through the Set
holding the order
together.
Hierarchy –

- Iterable – lang package. Only one method iterator().

 List – handles ordered & sequential list of objects.


o You have the control over where to insert an element and from
where to remove an element in the list.
o Elements can be inserted at a specific position using integer index.
Any pre-existing elements at or beyond that position are shifted
right.
o Elements can be removed from a specific position. The elements
beyond that position are shifted left.
o A list may contain duplicate elements.
o A list may contain multiple null elements.
Methods of List interface –
All 15 of Collection interface inherited to List interface
+ another 9 methods added in List interface.
1) E get(int index)
2) E set(int index, E element)
3) void add(int index, E element)
4) E remove(int index)
5) int indexOf(Object o)
6) int lastIndexOf(Object o)
7) ListIterator<E> listIterator() -> returns a list iterator over the
elements of this list.
8) ListIterator<E> listIterator(int index) -> Returns a list iterator
over the elements of d list starting from the specified index.
9) List<E> subList(int fromIndex, int toIndex)
 Queue - handles special list of objects in which elements are removed
only from the head.
 Set -  handles list of objects which must contain unique element.
 Map - This is the one interface in Collection Framework which is not
inherited from Collection interface. It handles group of objects as
Key/Value pairs.

------ ---------------------------------------------------------------- -----------

http://www.java-redefined.com/2013/08/java-collections-internal-working.html

Array vs Collection –

Performance

Dynamic size

Homogeneous vs Heterogeneous
Generics

You might also like