Vous êtes sur la page 1sur 3

Collections

Collection Classes 1 . ArrayList Description 1)ArrayList extends AbstractList & implements List Interface. 2)It is a dynamic array & increase or decrease its size dynamically. It provides fast iteration and fast random access. 3)Eg : In Employee Management System, ArrayList can be used to add the employee Details and employee details can be added at any time. 2 . HashSet 1)HashSet extends AbstractSet & implements Set Interface. 2)It uses hash table for storage purposes and it can have at most one null element. 3)It doesn't guarantee the order of elements. 4)It will not store duplicate values. 5)Eg : In Employee Management System, HashSet can be used to store all employee id,phone number. It rejects the duplicate values. 3. LinkedList 1)LinkedList extends AbstractSequentialList and implements List,Queue and Deque interface. 2)It can add element at first,last and delete element at first,last and can obtain first,last element values. 3)It provides linked list data structures. 4)Eg : In Census, the family members added using linked list. The family can be added in first,in last and using index value,it can be added in between & process is same for deletion. 4. LinkedHashSet 1)LinkedHashSet extends HashSet and implements Set Interface. 2)It is a combination of HashSet and LinkedList. It stores the values in which they are inserted. 3)It can add and remove elements from the set.

4)It is slower than HashSet. 5)Eg: In sports, Player list is stored according to their joining date. The values can be retrieved in ordering in which list is stored in database. 5.TreeSet 1)TreeSet extends AbstractSet and implements NavigableSet interface. 2)It uses tree structure for Storage and uses comparator to compare the elements. 3)Elements are stored in sorted,ascending order. 4)Access and Retrieval times are faster. 4)Eg : In Customer Management System, TreeSet can be used to retrieve the names from database in ascending order. 6. HashMap 1)HashMap extends AbstractMap & implements Map interface. 2)It uses hash table to store the map. 3)It doesn't guarantee the order of elements. 4)It uses key and value attribute to insert element. 5)Eg : In Railway Reservation System, passenger ticket number can be inserted as key and details can be added in value attribute. Passenger details can be retrieved using key attribute. 7. TreeMap 1) TreeMap extends AbstractMap and implements NavigableMap interface. 2)It stores map in tree structure. It allows rapid retrieval. 3)Elements are stored in sorted,ascending order. 4)Eg: In Student Management System, TreeMap can be used to retrieve the student details. Student ID number can be used as key. Using key,details can be retrieved easily and in ascending order. 8. LinkedHashMap 1)LinkedHashMap extends HashMap. 2)It maintains linked list of the entries in the map.

3)It allows insertion-order iteration. 4)It is a combination of HashMap and LinkedList. 5)Eg: In Ranking System, Student names can be retrieved using rank key.