java collections frame work ppt
TRANSCRIPT
COLLECTIONS
LIST SET
MAP
Sorted Map
Sorted Set
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.
AddAdd AddAllAddAll RemoveRemove RemoveAllRemoveAll ClearClear ContainsContains ContainsAllContainsAll IsEmptyIsEmpty SizeSize ToArrayToArray ItretorItretor ComparatorComparator SortSort PutPut
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
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
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
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.
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
public List<City> SortCityByComparator(){CityService cityService = new CityService(new
CityDataAccessObject(AddressBook.CityFile));List<City> CityList = cityService.FindAllCity();Collections.sort(CityList , new
CityNameComparator());return CityList;
}