Section 11.4. General Collections Methods

   

11.4 General Collections Methods

JDK 1.2 added to the collections significantly. It can be difficult to keep them straight, because their names ( TreeMap, Map, HashMap, HashTable, HashSet ) are so similar.

The Collection interface defines generic methods that you can use with any of the specific collection types. These are listed in Table 11.1.

Table 11.1. Generic Methods that Work with All Collections

Method

Purpose

add(Object o)

Inserts the specified element into the collection. Returns true .

addAll(Collection c)

Adds all of the elements in the specified collection to this collection. Returns true .

clear()

Removes all elements from this collection.

contains(Object o)

Returns a boolean true if the specified element is contained in this collection.

containsAll(Collection c)

Returns true if all of the elements specified are in this collection.

equals(Object o)

Compares the object specified to determine equality.

hashCode()

Returns the hashcode for this collection.

isEmpty()

Returns true if there are no elements in this collection.

iterator()

Returns an iterator for iterating through the objects in the collection.

remove(Object o)

Returns true if the element has been successfully removed from the collection.

removeAll(Collection c)

Removes all of the elements in this collection. Returns true .

retainAll(Collection c)

Retains only the elements specified in the passed collection. All others are removed.

size ()

Returns the number of elements in this collection.

toArray()

Returns an array containing all of the elements in this collection.


   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net