3. COLLECTIONS
The main java collections are List,Set and Map
LIST
the list store the elements in sequential form. It stores the elements in the orderstores the elements in the order
they were added, similar to an array only growable. the list may containthey were added, similar to an array only growable. the list may contain
duplicatesduplicates
SET
A Set is a collection that cannot contain any duplicate values,store only unique
values
MAP
A 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.
5. Some of List Implementations are given below....
ArrayList
LinkedList
MixedTypeArrayList
ARRAY LIST
ArrayList is a resizable array implementation like vector
LINKED LIST
A linkedList is a doublyLinkedlist implementation and it may
provide better perfomance than arraylist
6. Some of Set implementations are given below
HashSet
LinkedHashset
Treeset
HashSet
A hashset is a set backed by a hash table. It extends from
Abstractset class
TreeSet
A balanced binary tree implementation. imposes an ordering on
its elements and extend from Sortedset interface abstractset
classes
7. Some of MAP implementations are given below
HashMap
TreeMap
HashTable
HashMap
A hashMap is a implementation of map hashTable and it support null keys and
values
TreeMap
TreeMap is a balnced binary tree implementation and imposes an ordering on
its elements
Hashtable
synchronized hash table implementation of map interface
8. 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.
9. 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
10. public List<City> SortCityByComparator(){
CityService cityService = new CityService(new
CityDataAccessObject(AddressBook.CityFile));
List<City> CityList = cityService.FindAllCity();
Collections.sort(CityList , new
CityNameComparator());
return CityList;
}