java collections frame work ppt

11

Upload: ranjith-alappadan

Post on 25-Jan-2017

253 views

Category:

Education


12 download

TRANSCRIPT

Page 1: JAVA Collections frame work ppt
Page 2: JAVA Collections frame work ppt

COLLECTIONS

LIST SET

MAP

Sorted Map

Sorted Set

Page 3: JAVA Collections frame work ppt

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

AddAdd AddAllAddAll RemoveRemove RemoveAllRemoveAll ClearClear ContainsContains ContainsAllContainsAll IsEmptyIsEmpty SizeSize ToArrayToArray ItretorItretor ComparatorComparator SortSort PutPut

Page 5: JAVA Collections frame work ppt

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

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

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

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

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

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