13 CollectionFramework

You might also like

Download as pdf
Download as pdf
You are on page 1of 74
13. Collecbion Fxomeloctl, : - DURGA SOFTWARE SOLUTIONS SCIP MATERIAL i ls An Array ic an frelered collection of fired no. out : ree t Of hemegene ' dete elements. ara te Can represent mubtipl— > The main advantage Of : abe, So thm deka lite op ke vals bey vate Slagle ve cole, Witt be Pmproved. : A i dlies of oljek Eyre MN A. Arrays one Fined in size Tes one ne creotie on arrow thew ds no chante Of inertating | deereatine “the sine ba zl on ont Jaguiisewnent: 3 Heme to WHE array concept fice in aclvance, Which mary not petite aboot. can held only hemegonsons dda tyre dlesonks, compultony we should knmo the 2 Aven 1 Studewt£ J Senew StudetCaooodl; eu 7 SCal ene StudekO)5 ~~ SCID enew Customer}; —s, > We can Aetolve tHE problem by vaing “Objet type Om. QO] et ojetcd aenen Objet Loooo]s Ae} ene Studett)5 ~~ AL =new Curtomerl)s —~ ) 3. Thee ig no tunderliging dat. ahrudtine fol array. Hence J Aeadiymade cleta suppott we can't expect: Fok evry sagutrcmenl” we have te WHE coe explicrthy , which ineveases Cor plonttay a Be programming. PLOT NO.S6, HARSHA CHAMBERS, SAI NAGARNEAR BIG C MOBILES, MADHAPUR-500034, MOBILE: 9505905786 a DURGA SOFTWARE SOLUTIONS SCIP MATERIAL —> To overceme the above Prcblewy of arerongs we should go do Callectiora. A. Collections awe qrowalde in nabike je, based on our Sepuirement we Con tneveate | clecreate the sine. 2. Collections can tolol both hemengene oud 4 hetiogenecus elem onls, 3. Every Collection claus ie Fmplementeal Lares! some. stanclard at. shuoliere Hens fot every Aequittment” Aeadtgmade tote Suppo a4 availa. Being a progremmet ne heve te vie tee metfiacd: & ye he aten'b responsible be fmplement> Any and Collestions > — Aecommended to He. 4. Array con hotel only: henregeneous cbite elm outt, net recommended “to ute. 4. Collediont Can told LI homogemects onsel helevo qemecns clement . 5. Collections Can Aolot enh, objet rk paimrbiver. 5. Arerenpy com had both primitives and objets. 6. Thee is no tanelesliging ate 6. Fet every Collection clars tnclerliging cleta Shruckiive ft available, Hence ne Can expect veadymade et support fot ay wivement: Shute Fo arrays, Hence We Cant tapet Aeadymade hati suppott fo arrays. PLOT NO.S6, HARSHA CHAMBERS, SAI NAGARNEAR BIG C MOBILES, MADHAPUR-S00034, MOBILE-9505905766 2 = : ed | Collections 2 DURGA SOFTWARE SOLUTIONS SCIP MATERIAL Col lettion :— sy ak te vagrsenk = group of objet as a single ewtily thin we cheulel go fot Cellechion. re SBE Alfio covetel olaues $ Taticpne hich can be uted j a Sin: entities. aegrienk a qemp op ole mse sage AG Gr - (ol Collection ——-> Contain’ Callection Fla— > stb Cétomelarel Template Lilueny ) “key Tabepaus af Colleen Fremmmoetts A. Collection eeeeereees 2. Seb 4. Sorted Set S Navigate Set Neg 6 Qneue to Map & SctkedMap 4. Navigate Map ae lle — ip we want to eeprresent” a qroup of fnclivioluol objeti os a single ent tan we Should ge fol Collection. — > In gore Collection thitpece is consi aleve os Aol ftp of Colleton Framewetl, "PLOT NO.S6, HARSHA CHAMBERS, SAI NAGARNEAR BIG C MOBILES, MADHAPUR-500034, MOBILE:9505905786 5} DURGA SOFTWARE SOLUTIONS SCJP MATERIAL —> Collection trterpace clefines the most qeeet metho which ake applicott fot ong Collestion object. Difference bl Collection omd Collection 3 — ribose Sw Collection ea ee Colletion 2 an frtupace which cao Le uted to represent eyponp of individusl objets as a single enti by. Collectient iu an wibiley cours prow iq jeva. util oats to lifine satel title ae fo Caecien ojo Notes Thee fc ne cencrele clas oShict implements Collection fabeaf ace directly. & bteeCE) > Eb ke He chi Pattee a Collection > Pp ne wot to -vyrrsen a qreup Of tndividust olf ti ; a oti whine dupticabis one atlened amd incertion ‘ | Adee presived they ne thoatd ge fol List. Collection CL) lov List (5) aw Arvemg ise LinkedLict(e) (“yt Chang close) teaew lew Stack an teat: / old vereton Netii— In trversion, Veetol 4 Stack clatter ave Ae - enginesteal “be , Peplewnent Lick Tatis frees PLOT NO56, IRSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-500034, MOBILE.9505905786 DURGA SOFTWARE SOLUTIONS 3. Set) i— SCIP MATERIAL, | Be fe the child Tnhefau of Collection, — Up we want te arepres et a rer Trclivichuel object os a. Binge enti hire duplicate rot allowed g facertion Ader Won't be presewecl Thon we thoutd ge At Seb Colledtiion CL) vee Set lt) 1a) HorhSet ©) lev Linked HoehSet- Ce) teuv 4: Sotbed HCD) —> gE fe the child Thterpace Of Sete CO) > ap ne wok te aepreut a qreup Of indivictul oljectr witkowk duglic ali aes chching to some sotting oreleg then we Shoutd go fe Soeteol Sof Ss. Navigedde Set Ct). Js ge fe the child fterbeue of Cotte er. | > BH cbfines scevetal metiods foe nawigetion pripores. by fav Nawic q | ' Tra hrle) few Cr) Set \" Sotte Lott) Callection CF) ve ————— PLOT NO.S6, HARSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-500034, MOBILE:9505905786 o DURGA SOFTWARE SOLUTIONS scuP MATERIAL 6. Queue CE) I— > Tt te the child Prtufpace Of Collection, / > ip ne wat be repre a Fee Oy Trobivictinal objects paid b precesing thin We shoutd ge dor Queue. Caltectiion LL) Noy) aan | N\ Bipcktng Queue le) |» Pach ity Block ing Graeme: L_» Limreed Blecking Quene pk ~— 7 ve ~~ — Nite!) above tedarbaces (Collection, List, Sur, SotbedSet, Nowig okies and Queue) meant fol meprerenting a grep of individ oljjecti amet we cast ure fot, representing Keys velue path 4 (L)im Sap ve ost te repre a group of bie ns kegevahe pairs tits we should ge do fap. 3 Bb t& wk child Mrupece of Collection. ed HashMap (ce) vy We _ | fates Map (c) LinkestHathMep Ce) Tuy TOT NOG HARSHA CHAMBERS, SAI NAGARNEAREIGC MOBILES, MADHAFUR-500034, MOBILE:9S05905786 L. 6 1 ' i ‘ | | ; \ } | 1 @. Sorted Map CE) —> zt fe the chill Trhefate of Mag. , ; f > Thre wort be arepreesent a per bag value. poes aecovclivg te some sothing Adve of ys thn we Should Je fA Sctted Mop, %_Nawig alle Map CE) >— > Be te the child Peterface of Sotted Map. — > Ee afin somtel methocls fer nawigaction popes. I. alae SertenMapCr ) \eav NanigableMap CE)" Trev * 7 “Free Map Cc) ee lav Notci— @n Collection Framework | the follow 4 a Chorealine 4, Enumeration CT) , © 8. Pictionary CAC) oO 3. Veotod 6 5 4. Stack concrete chasses ( ) © 5. Hoshkable & Propestivs A TLOTNOSe HARSTN CHAMBERS, SAI WAGARNEAN BICC MOBILES, MADHAPUR-S00084, MOSILE:9505905706 Lo 7 {98450650568 140N "F£0005-UNAVHAVH ‘Sz 1IG0N 9 DIM UVANUVOVN IVS 'SUSEHVHD VHSUVH9S'ON LOTa LiskcE) \ Collestion CL) 2 Set CL) aA ae hay a ee wey ve Prrvog Lice) “! eae SNOLLMIOS 3uYMLIOS YOUNG somal eal new a ane Pracaity Btocké fey = + Prtet CO Uneed Btecteing Quant cy oS ts wh HashMap Cc) BearengA) ) EEE pe Mop. ots Nefe A. Com porvenbe CE) oo ne weg voces ond 2. CompayetoACt) needtahMapte) NavigaLaMop(t) web terblede)| Cudioes Tdosdity Hou Mapce | hew how TreeMap (¢) baw | 4. Enumeration (tL) A Etater (5) 3. List'TtervatoL Ca) ‘TwlusLvw dns DURGA SOFTWARE SOLUTIONS SCIP MATERIAL, A. Collections — 5 Up we wont te repracnt 9 qup oh Inclivduat objects os a single ect wthen ne theuld go for Collection Potit pure, i > Collection Tterprace defines the med- Common methacls vohich | me applicale fe cad Collection objet } ~The foltensing iy the List ef rnetbicle present” Trticle. Coltestion j Endesfpace. 4 boolean add CObjet o) boolean add Al (Collection ¢) beoten remove Cobjet o) \ ! » bovlan removeAll (Cotlestiin ©) I] Te temove oe G boeken tutain At (Collection c) |] To remove all objedtt tacpt votd clear) thew pret inc bookan contains (Oljuto) boolean contains Atl (Cotleation c) ~ bevlian teEmptye) 10. fro sizet) + e a u Obj eter torwagt): 2. Ptetot feeratotoy Noti!— There te ne conoreti clas which Tmplomnents Collection Pderpore Licedtty, & List i us ae te the child Intubace of Collection, > tp we wast fy represent a group Of Srcliviclunl objet” 1 hae ctupticalts cove alowed and triethion ocr preserved key we Should ge fet Listy PLOT NO.S6, HARSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-S00034, MO! 4 ee z > crectis on empty Arg ict DURGA SOFTWARE SOLUTIONS een —> We Con preseeve fneertion oct £ chifferectiotr hu plitate objets by vting Trcler Hones Fretra will play wert fmpettat Aol in List > Lite Pterfprce olefins the _ Lpecific mmetKacle, 4. void add (int tndea, Objet o) 4% boolean ode) (ft tneler, Collestion c) 8. Objub gerCint tncter) 4 Objet remove Lint Troler) 5. Objet cet-Cint- frelon, Object new) |] te veplac- The elemed prose ot cpecitied freter with previcleel Objet ome felitens oleh object 6 ink tnderOf Coljed¢) |] reliwns Inder of first aceuwence of. “o 4. the lat TndearOF (objeto) 8 List teyedot best TD htotot 0)5 a. Prva Ltete oe A. The Undluebying — olata ctrucliiive fot. Anau itt fe Retixatle of Growotle vray. © Duplicate objets ave aLowedl. 3. Ensetion Ader wit be preserved. % Hetsrogemaowt objeti ane‘ alowed. CEacpt Trost + TreMap, evagichie huttegeneous objets ave allewect), 5 Nutt treetion ic potsibe. Comatrutors i o Ane Lit Lene 4 PLOT NO.S6, HARSHA CHAMBERS, SAI NAGARNEAR BIG.C MOBILES, MADHAPUR-S00034, MOBILE osoev0e7aG 10 nee DURGA SOFTWARE SOLUTIONS SCIP MATERIAL > Ef Army Lic wreaphes mar. tapacily a new Arraylick abject | arn be erent wate Fe om oN) @ fragt: ice Lene wo deat bot ft, specified feuitee > Creatss om empl Array litt oat ott ep | ma Lick CEatvection «); 0 Tague Ee ei reat f& tk given Colleition => Crenbis an omplg Avmmyline objet + # ae Fb — ertion Hig Collection > Thy conthuetel meant fot ‘noted — Con A410) abject. Ear impart jova.util ts claws Avay LictDemo 4 es vm) 0 List Lene ArrmaylistO; Lradd ("A")5 te add (10); ti add CAS he add Cnutt); Sop; => olf: CA, 10, 4, not] Le semovet2); 6.0. p(L)5 => olPe CA, to, oct] Leaded C2, *m); Jada Cn"): So pCt); pol: [A,10,M, mult] i PLOT NO.S6, HARSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-S00034, MOBILE:9505905786 4 } t i i | 1 r DURGA SOFTWARE SOLUTIONS SCJP MATERIAL > Uruadly we can ate Colleton ty held £ tramp dle (objects) dro one Location te ancthit Location, —> To psovide suppott: fot they ortquivernent- eey Collection | chars Fnplementt Cefalinelle £ Cloneatle trhapates. bay Prog Lick 4 Vertor classes Pmplementr RandlemAccers Frteuface So thel Ke can any noncem element With te same Speed. 2 Hones ArvagLict iy bet fuitable if emt tryed operctiion fs Kebrieyal opustion, > RimdemAcees fotesfase presect to Jovani pakage oa douint contain ong wmetikeclt, Hense fe fe Masket Tnterbace. ext PerragLict Lane Arraglterdd; Linked Lia Lanes Linked List Os S.o.p Ch, tattonceoh Geatolinalle) 5 <> elp rtm So: p (hi tretanccol, Cleneable); > alps tre S.op (Ay tretanmwep Ramdem Aces): =p OlP i -foltt- es Soop (4 Tattone cy RondomAccey)): a> olp £ true. Dibteremees bly foray List ancl Yeetot Arragl iit Veth 4. No methad pruest fnstde 4 Gray method prised frufele Arve Lick te Synehnonized Vectot Te Stgnebronixed. 2 At atime maltipte threade ave | AP a time oly ore Hyena alowed ‘bo optate on Arreag id cUrwed te opercta on Vector objet: jet, Cienubtancenily. Honte AL. |Hemee Veetot objet te bows akjet fe mat Threnel Sebe, Thaced obe- 3. Relabively petbormamce te high [S- Reabively pabormence Fe Low. ! t ! | 1 | I | i ) | | | | | PLOT NO.S6, HARSHA CHAMBERS, SAT NAGARNEAR BIG C MOBILES, MADHAPUR-500034, MOBILE:9S0S905786 1 g- DURGA SOFTWARE SOLUTIONS SCIP MATERIAL Qi How tb quk Synchronized vertion oy ArrayLicé objet? auth — Araglitt object ite non-« chronixed Bub Arai By bp af ‘i om we can get symchvonined version of Arreg Lit objet May wttng the “following metkod of ex Array Lick denew Array lice Ys Lise &y = Collections, synchronixedl tet Cb)z Sgnchrmixedt ven —tgochronixed Veion version, Uy me cn get cgrabrontnad version Bak ond Hap object ‘9 ting the, —followstng methods ve aie wy ponecien oul [rae Stabe Map tynchronixed Map (Map m) ] Prenylitt a the heck choi we weont to perfor sebtievat ane ie ¢ ation te 4 A3 tovey te To the Woke choi ef ont frequent ca ; Ineettion ot detétion in the midelle beeow ie ic reuived sevval shibt- operations Fadeunallg. b. Linked Lice 2— A. The undetging late strucbire iy dewle Listed List: 2 Dntection over fs precevedd. $+ Duplicate objectt ane allowedt. 4. Hettregene ons oljetd ate towed. PLOTNO.S6, HARSHA CHAMBERS, SAI NAGARNEAR BIG C MOBILES, MADIAPUR-SO0031, MODIIESEDSOOCT NE 3 DURGA SOFTWARE SOLUTIONS 5. Null Preection te possible. 6 2 ont — Setiabizatle ond Clenealle trtupbaces, Lut not SCIP MATERIAL Landem Access, ' . | te Bet cheie if oud. cforep tent” cpastion te Ingestion oA deletion fy “the mite, | font feval. B Wetek chee of out frequent opustion fe -rebtieu. Construetos 6 @. [Unkedlitt Lene LinkestList dd; crentis an omplty LinkedLict objet crealix an tquivele Linked List object fot the gfvo Collection, — Us abg ne can ue Linkedl ict to implement — Stocks and Queues te pasvide suppott fot Phy regnivernent LinkedLiet clus defines “the following 6 specif methocls 4. void adelivet COlyet ©) 2. void addlast (Object ©) 3 Objet get Fircte GW Objet getLast) S Objet remove Firat-l > 6. hye vemeveLast C) Eat tempt jovanctils es clas Linteed List Demo 4 rs ov me) PLOT NO.S6, HARSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-500034, MOBILE9505905766, Le a r DURGA SOFTWARE SOLUTIONS LinkedList Le new Lintedliste ys dradel (etargas); - ds add (30); Le add (s, ar): de tek (o, *Sefpware") 5 tract Co, “veertey); AvvremoveLoxt( ); Ar adel Ficctt Yece); ) C. Veet 1 AL The unduabying chaste chucbiwe fe Resinable ovrarg axraug. Tnterbion. der te presewed 3% Duplicate objet ave allowed. » Heterogeneous objets one aUowed. Natt treeettond fe poscitle. >a F 4. vemy mettsd present trtide veetot te Veelot objet” ie Thiead Cafe. Conchuctors 3 — @ [wear ve neo Vector; | ag 1S ea D> ows [ccc, venky, eophwore, 20, null ] SCIP MATERIAL , vie¥ | 20, null, Ae acted (nut); cee venkey, aD, 3 am A Gravalle Enploments Sertalinalle , Cloneatle. £ RondemAcars intrpacesr, synchronined comet hence, Creal an empty Vietot objet Wilh olefoabt Pnitical PLOT NO.S6, HARSHA CHAMBERS, SAI NAGARNEAR BIG C MOBILES, MADHAPUR-S00034, MOBILE:9S05905766 DURGA SOFTWARE SOLUTIONS SCIP MATERIAL — > Once Vector eschy ft mas, Capacily Han a new Vector okject win be Creates wile [poe epee = 2 core pea] @- Vato vane Veett Unt thitiol capacity); PO. Vactot venev Vado int titialeapeeily , tah tnevementet capacity )5 ®@.~ Veet vere Veetot (Collection c)5 ieee 4. To add elements adel (Object 0) — > Cllection add Cit fnder, Objet ©) —> Lise add Cloment (Objet 0) —> veto 2. To remove element Aemove (Objet e) —> Collection Aemove Element (Object ©) —> Veetot Semove (nt Tnder)—> List Remove Elemente (ft fncen) —> Veet clear()—> Collection Acmove AU Elements () 5 Veetot- B. To Sobvieve clmentz from the Vietol Objeb aet Chet Inter) —> List Objet elomenb4t-Cfict’ toler )—9 Veet Objet firttElemenct¢.) —> Veet Objet lest Etemert-L) —o veto —_—— PLOT NO.56, HARSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-500034, MOBILE:9505005766 16 rg ee ea DURGA SOFTWARE SOLUTIONS SCIP MATERIAL ' 4 Some othr methods int ciel) Trt capacity) Enumeration elemetit) Se impott Javea. whi a5 cats Vectot Demo 4 Pt ov me) o Veetot Venen) VeetotO)t S.o-p Cv. capacity cy); => olp + 10 flit fat; teeto; Tr+) : ViaddElementCi) 5 S.0-.p Cv capacity 0))3 => 2lp 210 Vi aalel omert (A ")5 Sop lu tapactty es); => ofp :20 S-0-p0V)5 => olp: [1,2, 3,---. .-,10, AJ ali al. Stark 2 —> Bt iy the child clot of Veetet, ; > Eb ie a spetabiy cbstqned chars for Lost En Fivst_ Out IFO) ord. Constauetel §— soci eee ©, \Hak sone eek d;\ ——— Methods 2— A. Objet pushCokgeto) to tntat an objer Fitts the = Stack Ne TLOTNO.S6, HARSHA CHAMBERS, AI NAGARNEAR BIG C NOUILES MADHAPOR 500038, MODILESSOSB0S7O0 7 a | DURGA SOFTWARE SOLUTIONS 2 Objet pope) “hy semove & velive tip of the Stack 3 Objet peko) te CET top of tke Stack Without removal 4 boolean empty C) crelting bout, if stack i empl 5. Fue featch (Objet o) wrbiiene offedl, if the clement Fe arailale 0.10 wetrne at impott jova. util; | clats Stoo Demo L ps v mt) ce Stack(); S. posh COA; S. puch (1B); S posh ("e's S.op (3); => lk: £4,8,¢) Scop Cts Search CA") => OUP? 3 S.orp (scotch Cz); => elp: s y The 3 curicte of Jawa 2 > We an ue curtol te get objely one by ome drow Coll ection, — > There are 2 Mpa of curios availabe. bo Tava. ‘LOT NO.S6, HARSHA CHAMBERS, SAI NAGAR.NEAR BIG C MOBILES, MADHAPUR-S00034, MOBILE Ss0e00a7 06 te SCIP MATERIAL ———————

You might also like