0 ratings0% found this document useful (0 votes) 30 views14 pagesJava Collections Framework
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
oe LHo1/ 20 oad Poet
ge Collections froom enor =
Earp a nplements,
K ee | ; :
eatends
Desk os
Cay ee"
Peer eee et
‘ ee ee acre
implement Tn Plem ents
1
: Fmplemens re
ai Dee inzed Hosb Se
x
1
implements gatends
1 ; Bal 4
ifyectos] Arw {Deque ‘Sorted Ser |
&
one 1 inp ements
aed Map | TTreeSet
\ S, Snes B:Date
Collection Grameworne in Jove:
PHA ashen eam nore ss CE
of Severso) Ancers faces € Closses . Collections
are wp of obvects dhot can manipulwe
od a single unit. Gt Pro he ao ean fo sioee
OE ganice + Proceas Joya. erticiently-
Some ey used Collection Types obe-*
1. List
“otersface alesse? |
2. Set 5 é
Eke Colleer ap Prrroug List
4. Queue list Unked List
s- List Mop Hogh et
6. Unked List sek Linked HoshSet
4. Stack Queue ;
z ihe Tiewatod setae
9- HoabMop i HoahMee
ListTtetatoe
LinkedHoanlop
TreeeMap
Priom ae yen
Collection
~Tnreefaces:
i) Collection
—" 4 acts 03 Root tnteeface,
Ady paclades subihtetfaceg o& List, Set) Queue.
= Classes ImMPlemenri;
eo Ba Collection include Arrreogl ct,yr
pat
Ss eub- fnteéface of Collection
ee 1s
HF apres ene oredeted collection with index-hord
access. ; o
_ prraylist , Unkedlist Implements List interface.
gy allows duphcote elements.
— use cose. “Jt is guitcrble fon Scenomos whese
otdee mortees & cepetition of elements Is alowed,
2.9, loPo List
— In ToDo List we Keep teack of dosks
complered by a person ovee a time.
60 it can Chaser duplicate THES 08
a dosk Can be Completed multiple times.
a0 Lict 0);
- Dot: Element Type Shouteh Can be an type for
FSpecitic deta You wont to Atore crn ou
Uist. e.g, Sting, Great, Object
enernics cilows You to create
Oe jist, Srsursti g or the List
entain. elements oy Specibied TyreadSer +
— Ser Ftemface is Subiotersface ob Collection.
— Dt represents unomdeted collection ob
unique elements.
SAT kes not low duplicate Volues.
— Tits used where You Need a Collection with
De duplicate yalues ¢ omdeé of elements
1S Not significcunt -
Real Time use Case: Useé Registrzation
we can use sez interface fow uses Be aerearon
Whete set ensuyres drop oa Unique Users
ape Storr eo} x
Maze:
Set set-Name= new Harbéer<> C5
— HoshSet, LinkedHoubSet, TneeStt are common
Clagses which Implements set inteeface.
3 Queue!
— Queue intenface 1s subinteéface oF Collection
— Fis a collection designed fors Holding dlements
Prior fo Processing.
FH follows Fimst-Ty-Firsst- Our (FIFO) ondee
Prriortyqueue, UinkedUst ame the common dlegses.
T's weal for doses of Procesges that
needs to be ccecuten! Jn O@ SPecitic otdes.
CFEFO)
Siynroze :
Queue quevetlarne = new Linkedlist implements: st ¢ Dequene in teéfaces
_ Repeesents 0 Lswad-Ust 28 Doubly linked list thas
allows forx efficient Aementr Inéerstion daperavall
Sts te teens oon a
inkeo Ii ON- Contisuous in memo a4
Ftorsec] ot different m Moray Inearant 0 ne
— The elements are Hore eo} with Polnieés
- dt 3s implemented on heap emer.
Firuchuse of Linked List:
head e—>
e— |Name
' Neat
je2eet |e>—> |Namel
[Neser | rut)
> Unked List consist ot a data element caled a3
Nede.
> Nede consists two tields
Dd one hos data
second nos defeeence /addmess oF Mert. ree
then the address
ode «ill be
Tt there ts no next node
dhot keeps refeeence ot reet ™
YD
es3) Vectot :
~ G18 a clots which implements Ust interface ¢
eetends the PAbsteactLlist Class .
Vectoe is synchrroniced. qhe methods of Vectos
Class one “bnead safe, making it suitable for
Fituatlons where multiple th Is one aueerd
the Collection Concurrently.
— Uke Borer list Vectors car dynein ically Resize
sels .
— Note: ies
List 18 always Prefersmed for its
eu cary oveé vertos.
Stack :
Stack Js a closs that represents a lost-In-Fiest-Ou
Stack of Objects,
Stack esetends Vectoe clogs. ¢. inherits Mies :
but dso add a felv stark elated metneds
Elements dwe added ¢ Semoved from che
top oF Stack
methods :
Push) — add dement
PoP () — €emoves elem ent
emPH) - Checks IF Back js Orn pr
Pecux() - detursns The eement
Stack without pemovin reset ve2 prety Queue:
_ mplements the Queue interface.
_ BR represents O priorit queue .
| Elements ame éermived Msed on Preto >
© athe default behaviour ts 4 have elements
ordered in thei natural ondet, oc ahe,
smaljest element hos PEPE Priorita.
- we con also define a etigtom comporratoe do
define the ae ge based on Specitic eriteria,
= Je Is Commonly Us 19 Scencurios where
elements need “to be processed in ondee of
prionity Such o§ task Seer ay
coding ‘ct Dijkstea's algorithm “fo
dhe UShentest Poth jn seek
Huff an
RB ipacing
Methods -
- Offee Celement) : Inserts sPpecitic element
- Polit) | eetrives 4 eemoves the head: ot j
Proiorsity quexe- ‘
T PRERO) : Rotry\es bur not Removes the head o&
erat queue.
DSO
AXSe ate chop implements Deque Intee face,
— dtris tesicable arora -bos Implementetton ot
dleuble- ended queue . .
— A Deque is a queue that allows elements 7 be
added c& temoued frorn both ends ,
= ale dynamical] pesices itselb a2 elements ane
added ot Ses
~ unlike vecios ¢ stack IF ts not syomoninsd
Which can tesult in bettee pemforimance
where Bychronicatlon 1S Not Required.
Methods :
- addfirst @lement) : els an element to front of
eque .
~ addlost (element) : Adds on lement to end ot dai
~ Aomovefinst(dement): Zemove 4 Eetunn element yey
- €emovelast (element) ) emove ¢ éehinn element ot ont
z gerfiesto : Setmives QU doesnot removes the ob |
ment oddhe freon & ot deque,
z gerlosk Eetrives but does not Eermaves the
Sortareg at the end oe
deque,YS
pst :
Atos class imple
TOS odes aonrect!
ments Ser intersface .
on oF unique glements where
- He or element is not be 6
- +, bosed OF HoshToble 4 it uses Hoahing meckonis, :
yo efficient! stone 4 eetrive elements .
invernally user HashMap to sore Hs
posbSt
elements:
5 crmeated ‘the HashMap obiect
tinen MasbSet A
also get created by HosbSet .
_ Fe doesn't lows duplicate lements .
- q an hold only one null value.
Ft is not nchronized.
then we odd an element to bashset then
Be AO.osed anime Ss Tea
+O gore the element 4
‘
; the element 8 ce ’
| a3 its value 4 | Conétcint "present
eg, 5
Setdsinings
oshset = new +
03 K
hoahSet. &dd ("pope"); bSer<7 0);
Poth. add spp) mols
rap. Put("Bpple”, pREsENT)== Null
| key]
pnt reser
I
Frreena} HosnMap obseri ae
HashMap :
— UnkedHosbSet is a clos dhot eeetends HoshSet 4
implements the Set Antereface .
— tt provides collection oF Unique elements .
- GH mointaing the Ondeé of ISentlon of
elements. }
= dts a hybrid doin steuctuwe thot combines
& HathToble vith a UnkedList to achieve,
both uniqueness 4 predictable iteRoation oxdes
— FH user HoshTable foe stoeage 4 O1s0 maintain,
Unkedlist o* entries.
oTinee Set «
TreeSet is a class thar Implements the
Navigableset intetface 4 oetends Abstraciser clos
H provides collection oF unique Gemenis only,
€lements ame stormed in sorted oedoe
eithers baged on cthelry Natura) ordeging o€
Using O “cUstom Comparrateé Provid Ge)
time of creation.
tH ioternally wes Balanced bincur
Tree fory Sfocion aces
Clemens in aa redez
Search
“TreeMap |
= TreeMap tmplements NavigableMap inteeface 4
gntonle an PAbsteactMap elags .
Bornes elements in sorsted cadet, elthed bose
n Pele ane o& by custon compatsatot
aise suing Gane adh
— Each key ie
TeeeMap must be unique,
~ Interna) used b
Han .
+o ice ad ced bin
Bierce Hoe
sto :
Sorted sens Bend 7S ve ‘€lements in