Java Reference
In-Depth Information
List<T> Interface
Package: java.util
Ancestor interfaces: Collection<T> , Iterable<T>
All the exception classes mentioned are the kind that are not required to be caught in a catch
block or declared in a throws clause.
All the exception classes mentioned are in the package java.lang and so do not require any
import statement.
CONSTRUCTORS
Although not offi cially required by the interface, any class that implements the List<T>
interface should have at least two constructors: a no-argument constructor that creates an empty
List<T> object, and a constructor with one parameter of type Collection<? extends T>
that creates a List<T> object with the same elements as the constructor argument. If the
argument imposes an ordering on its elements, then the List<T> created should preserve
this ordering.
public boolean contains(Object target)
Returns true if the calling object contains at least one instance of target . Uses target.equals
to determine if target is in the calling object.
Throws:
ClassCastException if the type of target is incompatible with the calling object (optional).
NullPointerException if target is null and the calling object does not support null
elements (optional).
public boolean containsAll(Collection<?> collectionOfTargets)
Returns true if the calling object contains all of the elements in collectionOfTargets .
For element in collectionOfTargets , uses element.equals to determine if element is
in the calling object. The elements need not be in the same order or have the same multiplicity in
collectionOfTargets and in the calling object.
public boolean equals(Object other)
If the argument is a List , returns true if the calling object and the argument contain exactly
the same elements in exactly the same order; otherwise returns false . If the argument is not a
List , false is returned.
public int hashCode()
Returns the hash code value for the calling object. Neither hash codes nor this method is
discussed in this topic. This entry is only here to make the defi nition of the List interface
complete. You can safely ignore this entry until you go on to study hash codes in a more
advanced book. In the meantime, if you need to implement this method, have it throw an
UnsupportedOperationException .
boolean isEmpty()
Returns true if the calling object is empty; otherwise returns false .
 
Search WWH ::




Custom Search