Collections in Java
Collections in Java
Collections is a generally called handling group of elements. Its used to add the Elements in dynamically in memory and also arrange the Elements in structure. It allows different types of collections to work in a similar manner and with a high degree of interoperability. Implementation of fundamentals of Collection Process are Highly Efficient.
Collection classes are used static methods to operate collection algorithms.
Implementation of classes
- class HashMap implements Map
- class TreeMap implements SortedMap
- It is an Unordered Collection. It returns the elements in ascending order
- It does not allows duplicate to store.
- No need of index to store elements in set
- Ordering of elements done by sorted set interface.
It stores the element based on hashcode value of the object. So it returns the value in hashcode format arranging i.e ascending order of elements with hashcode. It allows different type of elements.
It stores the element based on ascending order. It allows only similar type of elements. Using TreeSet we can retrieve the elements in descending order also.
- It is an ordered collection. returns the same order we enter
- It allows duplicate elements to store.
- It stored elements based on index value.
- ArrayList is implemented from List Interface.
- It allows to store different types of elements when compare to array.
- It also allows increase and decrease the elements dynamically.
- It store the elements based on index and print the same order we given.
- It allows user to store duplication of elements.
- Vector class extends AbstractList and implements List, RandomAccess, Cloneable, Serializable.
- It is based on reserved memory storage called capacity.
- It will maintain default capacity of 10 bytes. It allows user can define their own capacity based on constructor.
- It allows to retrieve first and last element respectively.
It is similar to hashtable storage. It allows elements to store based on key-value pair. Here it doesn’t allows duplicate keys. Values may duplicate.
It allows to retrieve keys individually, values individually and key-value pair.
It is used to retrieve the keys in ascending order mappings.
Mostly this kind of interface used in dictionaries and telephone directories application.
It allows different types of keys to store elements. Ordering keys based on hashcode of the keys object.
It allows similar type of keys to store elements. Using SortedMap to arrange keys objects in ascending order.
In Java Collections Framework using reading elements in collections are following Interfaces
- Iterator Interface
- Enumeration Interface
It will obtain all the elements of a collection at a time and check them in sequentially by itself. It will used for all type of collection classes.
- boolean has Next() – It is used for check the next elements in the collection and place the cursor in the position.
- E next() – It is used to returns the next element.
- void remove() – It will remove the last element given by iterator.
It will obtain only one element from the collection at a time. It familiarly used for Vector and Stack classes.
- boolean has More Elements() – It returns true if next element is available for extract.
- E nextElement() – It returns the next element in the collection.