JAVA Collections frame work ppt
-
Upload
ranjith-alappadan -
Category
Education
-
view
329 -
download
12
Transcript of JAVA Collections frame work ppt
![Page 1: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/1.jpg)
![Page 2: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/2.jpg)
COLLECTIONS
LIST SET
MAP
Sorted Map
Sorted Set
![Page 3: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/3.jpg)
COLLECTIONSThe main java collections are List,Set and Map
LISTthe list store the elements in sequential form. It stores the elements in the order stores the elements in the order
they were added, similar to an array only growable. the list may contain they were added, similar to an array only growable. the list may contain duplicatesduplicates
SETA Set is a collection that cannot contain any duplicate values,store only unique
values
MAPA Map Is a collection that store key value pairs, A key is an object that you use
to retrieve a value at a later date.
![Page 4: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/4.jpg)
AddAdd AddAllAddAll RemoveRemove RemoveAllRemoveAll ClearClear ContainsContains ContainsAllContainsAll IsEmptyIsEmpty SizeSize ToArrayToArray ItretorItretor ComparatorComparator SortSort PutPut
![Page 5: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/5.jpg)
Some of List Implementations are given below.... ArrayList LinkedList MixedTypeArrayList
ARRAY LISTArrayList is a resizable array implementation like vector
LINKED LISTA linkedList is a doublyLinkedlist implementation and it may
provide better perfomance than arraylist
![Page 6: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/6.jpg)
Some of Set implementations are given below HashSet LinkedHashset Treeset
HashSetA hashset is a set backed by a hash table. It extends from
Abstractset class
TreeSetA balanced binary tree implementation. imposes an ordering on
its elements and extend from Sortedset interface abstractset classes
![Page 7: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/7.jpg)
Some of MAP implementations are given below HashMap TreeMap HashTable
HashMapA hashMap is a implementation of map hashTable and it support null keys and
values
TreeMapTreeMap is a balnced binary tree implementation and imposes an ordering on
its elements
Hashtablesynchronized hash table implementation of map interface
![Page 8: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/8.jpg)
Iterator enables you to cycle through a collection, obtaining or removing elements. Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection.
![Page 9: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/9.jpg)
Collections.sort() static Method:
public List<Person> SortByAge(){PersonService personService = new PersonService(new
PersonDataAccessObject(AddressBook.PersonFile));List<Person> personList = personService.FindAllPerson();
Collections.sort(personList, new Agecomparator());return personList;
}
here the collections that keeptheir elements sorted and the iterator are guaranteed to travese in sorted order
![Page 10: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/10.jpg)
public List<City> SortCityByComparator(){CityService cityService = new CityService(new
CityDataAccessObject(AddressBook.CityFile));List<City> CityList = cityService.FindAllCity();Collections.sort(CityList , new
CityNameComparator());return CityList;
}
![Page 11: JAVA Collections frame work ppt](https://reader035.fdocuments.net/reader035/viewer/2022081417/5888490f1a28ab951c8b4a27/html5/thumbnails/11.jpg)