Colections in Java:
The collection frame work provides a set of interfaces ( Collection, List, Set, SortedSet)
The collection Interface
The collection interface :
* Objects can be added using the "add(Object x)" method. So any type of object can be added.
* We can use "addAll(Collection c)" method to store the elements of a certain collection into another one.
* "remove() and removeAll()" can be used to remove objects from the collections.
* "contains() and containsAll()" are methods that are used for the purpose of checking prescenece of one/all object in a collection.
* "toArray()" mehtod is used to convert the collection to an array
* "iterator()" returns an iterator over that collection.
The List Interface
The List interface extends collection and presents the behavior of storing a squence of elements. A list may contain duplicate elements.
* Methods like "add(), addAll(), add(int, Object) addALL(int, Object)" are methods used to add the elements either at the end or at the specified index.
* get(int) is used to retrive the object from the List
* indexOf() and lastIndexOf() is used to get the index of the object
* subList can be extracted specifying the start and end index. List subList(int, int)
The Set Interface
The set interface is the interface that extends the behavior of the collection.
* Elements in the set are unique. Duplicates are not allowed.
* It returns false if we try to add a duplicate.
The Sorted Set
Sorted Set interface extends the set interface and provides a behavior that elements in the sorted set are stored in ascending order.
* first() returns the first element of the sorted set.
* subset(Object start, Object end) returns the subset of the elemtns from the sorted set.
* comparator() returns the comparator of the sorted set.
* last() is used to get the last elemnt of the sorted set.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment