1 / 33

COLLECTION

COLLECTION. Imam Fahrur Rozi. TOPIK. Pengenalan Collection Collection Framework Collection Interfaces Map Pengambilan element Iterator ListIterator Enumeration. PENGENALAN COLLECTION.

lynsey
Télécharger la présentation

COLLECTION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COLLECTION Imam FahrurRozi

  2. TOPIK • Pengenalan Collection • Collection Framework • Collection Interfaces • Map • Pengambilan element • Iterator • ListIterator • Enumeration

  3. PENGENALAN COLLECTION • Collection jugadisebut container merupakanobyek yang menyimpanelemen – elemenobyekkedalamsatu unit • Dalam Java collection digunakanuntukmenyimpan, menerimadanmemanipulasiobyek, mirippada array. • Collection yang umumyaituHashTable, Array dan Vector telahadasejakversi JDK 1.2

  4. PENGENALAN COLLECTION • JDK 1.2 dansebelumnyatidakmemiliki collection framework. • Array dapatmeyimpantipe data primitifataupunobyek, tetapi Collection hanyamenyimpanobyeksaja • Tipe data primitiftidakbisaditambahke Collection, sehinggaharusmenggunakan wrapper class-nya

  5. COLLECTION FRAMEWORK • Collection framework merupakankerangka yang digunakanuntukmerepresentasikandanmemanipulasi collection • Collection Framework meliputi : • Interfaces : Mendefinisikan method dimanatiaptipecollection harusmengimplementasikannya • Implementation : Kelas yang mengimplementasikan interfacecollections, misalHashSetdanTreeMap • Algoritma : Method yang digunakanuntukmelakukankomputasi, seperti sorting, searching, menyimpandanmemanipulasielemen

  6. COLLECTION INTERFACE • Interface dalam collection framework merupakanpondasidari collection • Map danSortedMapbukanturunandari interface Collection. Map danSortedMaptetapdikenalisebagai collection, meskipunmenurutbatasandefinisi Java menyatakanbahwa Map danSortedMapbukantermasuktipe Collection

  7. HIRARKI COLLECTION INTERFACE

  8. Definisi Interfaces • Collection : sekumpulanobyek yang tidakmempunyaiposisiyang tetap (no particular order) danmenerimaduplikat. • List: sekumpulanobyek yang urut (ordered) danmenerimaduplikat. • Set: sekumpulanobyek yang tidakurut (unordered) danmenolakduplikat. • Map: mendukungpencarianberdasarkan key, key iniharusunik. Has no particular order. • SortedSet : Extend interface Set denganmengurutkanelemennya • SortedMap : Extend interface Map denganmengurutkan key elemennya

  9. Method Interface Collection • boolean add(Object element) : Menambahkanelemenpada collection, bilaberhasilakanmengembalikannilai true. • boolean remove(Object element) : Menghapuselemendi collection, bilaberhasilakanmengembalikannilai true. • int size() : Mengembalikanjumlahelemendalam collection

  10. Method Interface Collection • booleanisEmpty() : Jikatidakterdapatelemensamadalam collection makaakanmengembalikannilai true. • boolean contains(Object elemen) : Akanmengembalikannilai true jikaelementerdapatpada collection. • booleancontainsAll(Collection collection_A) : Akanmengembalikannilai true jikasemuaelemen yang adapadacollection_Aadapada collection.

  11. Method Interface Collection • booleanaddAll(Collection collection) : Akanmengembalikannilai true jikasemuaelemen yang adapadacollectionAberhasilditambahkanpada collection. • void clear() : Mengapussemuaelemen collection. • void removeAll(Collection collection_A) : Menghapussemuaelemen collection yang adapadacollectionA • void retainAll(Collection collection A) ( _ ) : Menghapussemuaelemen Collection kecualielemen yang adapadaCollection_A

  12. Beberapa yang kitabahas

  13. Set : HashSet • Elemenpada Set selaluunik. • Set menolakduplikat. • Elemen yang tersimpantidakurut (unordered) dan unsorted. • Interface Set merupakan sub interface dari interface Collection

  14. ContohHashSet

  15. SortedSet : TreeSet • Aturansamadengan interface Set menolakduplikat. • SortedSetadalahsubinterface Set. • Beda : elementersimpandalamurutan ascending  sorted

  16. ContohTreeSet

  17. List • Elementersimpanterurut (ordered). • Urutberdasarkanmasukan. • Menerimaduplikat. • Contoh List: • LinkedList : elemendalamLinkedListmasukdariawaldandihapusdariakhir. • Vector : a growable array of object. • ArrayList: mirip vector, bersifatunsyncronized (jikamultiple threads mengakses object ArrayList, object iniHarussyncronizedsecaraeksternal)

  18. ContohArrayList

  19. Contoh Vector

  20. Map • Menyimpanelemendengan key unik. • Satu key untuksatuelemen. • Key disimpandalambentuk object. • Map tidakbisamenyimpan duplicate key. • Map bisamenyimpan duplicate element. • Has no particular order. • Contoh: • Hashtable • HashMap • not syncronized for threads • permits null values to be stored

  21. ContohHashTable

  22. ContohHashMap

  23. SortedMap : TreeMap • Aturanmirip Map • Beda: obyektersimpansecara sorted berdasarkan key. • No duplicate key . • Elements bolehduplikat. • Key tidakboleh null value

  24. ContohTreeMap

  25. BaganPerbandingan

  26. Iterator • Iterasiadalahprosesmendapatkankembali(retrieve) elemen yang terdapatdalam collection. • Iteratormerupakan interface yang bisadigunakanuntukmeretrieveelemen collection.

  27. ListIterator • ListIteratoradalahsubinterfacedariIterator. • DenganmenggunakanListIteratorpada List, makaelemendapatdiambilsecara backward. • Gunakan method next atau previous sebagainavigasi

  28. HirarkiIterator

  29. ContohIterator

  30. Enumeration • Enumeration adalahvariasidariIterator. • Cara kerja Enumeration miripdenganIterator. • Method hasNext() digantidenganhasMoreElements( • Method next() untukmengambilobyekdigantinextElement • Diunakanpada Vector

  31. Conth Enumeration

  32. Kesimpulan • Collection menyimpan element tidakberurut (unordered) tidakadaduplikasi • List mengurutkan element • Set menolakduplikasi element • Map menggunakan key unikuntukmenandaielementnya

  33. KesimpulandariSegiPenyimpanan • Menggunakan array membuatpenyisipandanpenghapusanelemensertapenambahankapasitassimpanlebihsulit. • List mendukungpenyisipandanpenghapusanelemensertapenambahankapasitassimpan, tetapipengaksesanindeksmenjadilambat • Tree mendukungpenyisipandanpenghapusanelemensertapenambahankapasitassimpan, pengaksesanindeksmenjadilambattetapipencarianlebihcepat • Hash mendukungpenyisipandanpenghapusanelemensertapenambahankapasitassimpanPengaksesanindeksmenjadilambattetapipencariansedikitlebihcepat. Hash membutuhkan key unikuntukmenyimpan data element

More Related