java.util

Interface Collection<E>

All Superinterfaces:
Iterable<T>
Known Subinterfaces:
Bag, BeanContext, BeanContextServices, BlockingQueue<E>, BoundedCollection, Buffer, HandlerChain, IndexedRecord, List<E>, Queue<E>, Set<E>, SortedBag, SortedSet<E>
Known Implementing Classes:
AbstractBagDecorator, AbstractBufferDecorator, AbstractCollection<E>, AbstractCollectionDecorator, AbstractDualBidiMap.EntrySet, AbstractDualBidiMap.KeySet, AbstractDualBidiMap.Values, AbstractDualBidiMap.View, AbstractHashedMap.EntrySet, AbstractHashedMap.KeySet, AbstractHashedMap.Values, AbstractLinkedList, AbstractLinkedList.LinkedSubList, AbstractList<E>, AbstractListDecorator, AbstractMapBag, AbstractQueue<E>, AbstractSequentialList<E>, AbstractSerializableCollectionDecorator, AbstractSerializableListDecorator, AbstractSerializableSetDecorator, AbstractSet<E>, AbstractSetDecorator, AbstractSortedBagDecorator, AbstractSortedSetDecorator, Anchor, ArrayBlockingQueue<E>, ArrayList<E>, ArrayQueue<T>, ArrayStack, AttributeList, BeanContextServicesSupport, BeanContextSupport, BinaryHeap, BlockingBuffer, BoundedBuffer, BoundedFifoBuffer, BoundedFifoBuffer, BucketingService.CollectedList, ByteCollectionCollection, ByteListList, Chapter, ChapterAutoNumber, CharArraySet, CharCollectionCollection, CharListList, CircularFifoBuffer, CompositeCollection, CompositeSet, ConcurrentLinkedQueue<E>, CopyOnWriteArrayList<E>, CopyOnWriteArraySet<E>, CursorableLinkedList, CursorableLinkedList, DefaultMapBag, DelayQueue<E,extends,Delayed>, DigesterRuleParser.PatternStack, DoubleCollectionCollection, DoubleListList, EnumSet<E,extends,Enum,E>, FastArrayList, FixedSizeList, FloatCollectionCollection, FloatListList, GrowthList, HashBag, HashBag, HashSet<E>, IntCollectionCollection, IntListList, JobStateReasons, LazyDynaList, LazyList, LinkedBlockingQueue<E>, LinkedHashSet<E>, LinkedList<E>, ListItem, ListOrderedSet, LongCollectionCollection, LongListList, ManagedList, ManagedSet, MapBackedSet, NodeCachingLinkedList, Paragraph, PersistentBag, PersistentIdentifierBag, PersistentList, PersistentSet, PersistentSortedSet, Phrase, PredicatedBag, PredicatedBuffer, PredicatedCollection, PredicatedList, PredicatedSet, PredicatedSortedBag, PredicatedSortedSet, PriorityBlockingQueue<E>, PriorityBuffer, PriorityQueue<E>, RoleList, RoleUnresolvedList, Section, SetUniqueList, ShortCollectionCollection, ShortListList, SnmpVarBindList, Stack<E>, SynchronizedBag, SynchronizedBuffer, SynchronizedCollection, SynchronizedList, SynchronizedSet, SynchronizedSortedBag, SynchronizedSortedSet, SynchronousQueue<E>, TransformedBag, TransformedBuffer, TransformedCollection, TransformedList, TransformedSet, TransformedSortedBag, TransformedSortedSet, TreeBag, TreeBag, TreeList, TreeSet<E>, UnboundedFifoBuffer, UnboundedFifoBuffer, UnmodifiableBag, UnmodifiableBoundedCollection, UnmodifiableBuffer, UnmodifiableCollection, UnmodifiableEntrySet, UnmodifiableList, UnmodifiableSet, UnmodifiableSortedBag, UnmodifiableSortedSet, Vector<E>, XfaForm.Stack2, XmpArray

public interface Collection<E>
extends Iterable<T>

The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements. Some collections allow duplicate elements and others do not. Some are ordered and others unordered. The JDK does not provide any direct implementations of this interface: it provides implementations of more specific subinterfaces like Set and List. This interface is typically used to pass collections around and manipulate them where maximum generality is desired.

Bags or multisets (unordered collections that may contain duplicate elements) should implement this interface directly.

All general-purpose Collection implementation classes (which typically implement Collection indirectly through one of its subinterfaces) should provide two "standard" constructors: a void (no arguments) constructor, which creates an empty collection, and a constructor with a single argument of type Collection, which creates a new collection with the same elements as its argument. In effect, the latter constructor allows the user to copy any collection, producing an equivalent collection of the desired implementation type. There is no way to enforce this convention (as interfaces cannot contain constructors) but all of the general-purpose Collection implementations in the Java platform libraries comply.

The "destructive" methods contained in this interface, that is, the methods that modify the collection on which they operate, are specified to throw UnsupportedOperationException if this collection does not support the operation. If this is the case, these methods may, but are not required to, throw an UnsupportedOperationException if the invocation would have no effect on the collection. For example, invoking the addAll(Collection) method on an unmodifiable collection may, but is not required to, throw the exception if the collection to be added is empty.

Some collection implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements, and some have restrictions on the types of their elements. Attempting to add an ineligible element throws an unchecked exception, typically NullPointerException or ClassCastException. Attempting to query the presence of an ineligible element may throw an exception, or it may simply return false; some implementations will exhibit the former behavior and some will exhibit the latter. More generally, attempting an operation on an ineligible element whose completion would not result in the insertion of an ineligible element into the collection may throw an exception or it may succeed, at the option of the implementation. Such exceptions are marked as "optional" in the specification for this interface.

This interface is a member of the ../../../guide/collections/index.html"> Java Collections Framework.

Many methods in Collections Framework interfaces are defined in terms of the equals method. For example, the specification for the contains(Object o) method says: "returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e))." This specification should not be construed to imply that invoking Collection.contains with a non-null argument o will cause o.equals(e) to be invoked for any element e. Implementations are free to implement optimizations whereby the equals invocation is avoided, for example, by first comparing the hash codes of the two elements. (The Object.hashCode() specification guarantees that two objects with unequal hash codes cannot be equal.) More generally, implementations of the various Collections Framework interfaces are free to take advantage of the specified behavior of underlying Object methods wherever the implementor deems it appropriate.

Since:
1.2
See Also:
Set, List, Map, SortedSet, SortedMap, HashSet, TreeSet, ArrayList, LinkedList, Vector, Collections, Arrays, AbstractCollection

Method Summary

T[] toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
boolean
add(E o)
Ensures that this collection contains the specified element (optional operation).
boolean
addAll(E> c)
Adds all of the elements in the specified collection to this collection (optional operation).
void
clear()
Removes all of the elements from this collection (optional operation).
boolean
contains(Object o)
Returns true if this collection contains the specified element.
boolean
containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection.
boolean
equals(Object o)
Compares the specified object with this collection for equality.
int
hashCode()
Returns the hash code value for this collection.
boolean
isEmpty()
Returns true if this collection contains no elements.
Iterator
iterator()
Returns an iterator over the elements in this collection.
boolean
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).
boolean
removeAll(Collection c)
Removes all this collection's elements that are also contained in the specified collection (optional operation).
boolean
retainAll(Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).
int
size()
Returns the number of elements in this collection.
Object[]
toArray()
Returns an array containing all of the elements in this collection.

Methods inherited from interface java.lang.Iterable<T>

iterator

Method Details

T[] toArray

public  T[] toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Like the toArray method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs

Suppose l is a List known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:

     String[] x = (String[]) v.toArray(new String[0]);
 

Note that toArray(new Object[0]) is identical in function to toArray().

Parameters:
a - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of this collection
Throws:
ArrayStoreException - the runtime type of the specified array is not a supertype of the runtime type of every element in this collection.
NullPointerException - if the specified array is null.

add

public boolean add(E o)
Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if this collection changed as a result of the call
Throws:
UnsupportedOperationException - add is not supported by this collection.
ClassCastException - class of the specified element prevents it from being added to this collection.
NullPointerException - if the specified element is null and this collection does not support null elements.
IllegalArgumentException - some aspect of this element prevents it from being added to this collection.
Usages and Demos :

View More Examples of add(E o)
   1:   {
   2:     Collection c = new LinkedList();
   3: 
   4:         ...
   5:     for ( int i = 0; i < 5; i++ )
   6:       c.add( "" + i );
   7: 
   8:   }
   9: }

View Full Code Here
   1:     private Page page3;
   2:     private Collection list;
   3: 
   4:         ...
   5:         list = new ArrayList();
   6:         list.add("One");
   7:         ...
   8:         list.add("Two");
   9:         ...
  10:         list.add("Three");

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:     public void testDeepClone() {
   6:         Collection c1 = new ArrayList();
   7:         ...
   8:         Collection c2 = null;
   9:         
  10:         ...
  11:         c1.add(new Point(1, 2));
  12:         c1.add(null);

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: import java.util.List;
   4:         ...
   5:         ArrayList belgiumRegions = new ArrayList();
   6:         belgiumRegions.add(antwerp);
   7:         ...
   8:         belgiumRegions.add(gent);
   9:         ...
  10:         belgiumRegions.add(brugge);

View Full Code Here
   1: import java.util.Arrays;
   2: import java.util.Collection;
   3: import java.util.HashSet;
   4:         ...
   5: 
   6:     private static void assertUnmodifiableCollection(Collection coll) {
   7:         try {
   8:         ...
   9:             coll.add("Unmodifiable");
  10:             fail();

View Full Code Here

addAll

public boolean addAll(E> c)
Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
Parameters:
c - elements to be inserted into this collection.
Returns:
true if this collection changed as a result of the call
Throws:
UnsupportedOperationException - if this collection does not support the addAll method.
ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection.
NullPointerException - if the specified collection contains one or more null elements and this collection does not support null elements, or if the specified collection is null.
IllegalArgumentException - some aspect of an element of the specified collection prevents it from being added to this collection.
See Also:
add(Object)
Usages and Demos :

View More Examples of addAll(E> c)
   1: 
   2: import java.util.Collection;
   3: import java.util.LinkedHashSet;
   4:         ...
   5: 
   6:     public java.util.Collection handleGetRoles()
   7:     {
   8:         ...
   9:         final Collection roles = new LinkedHashSet();
  10:         if (this.getOwner() instanceof Service)
  11:         ...
  12:         {
  13:             roles.addAll(((Service)this.getOwner()).getRoles());

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Map;
   4:         ...
   5:         Object newValue = newResult.getValue();
   6:         if (value instanceof Collection) {
   7:         ...
   8:             Collection coll = (Collection) value;
   9:             if (newValue instanceof Collection) {
  10:         ...
  11:                 coll.addAll((Collection) newValue);

View Full Code Here
   1: 
   2:     Collection getAllEndPointsInApp(WebServiceEndpoint desc) {
   3:         ...
   4:        Collection endPoints = new Vector();
   5:         ...
   6:        Collection allWebServices = desc.getWebService().getWebServicesDescriptor().getWebServices();
   7:        for (Iterator it = allWebServices.iterator(); it.hasNext();) {
   8:         ...
   9:            endPoints.addAll(((WebService)it.next()).getEndpoints());

View Full Code Here
   1: 
   2:     Collection container = ((IncrementalSubscription)subscription).getChangedCollection();
   3:     if (container == null) {
   4:         ...
   5:     else
   6:       container.addAll(((IncrementalSubscription)subscription).getAddedCollection());
   7: 
   8:     Iterator iterate = container.iterator();
   9:     while (iterate.hasNext()) {

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: import java.util.Collections;
   4:         ...
   5:             }
   6:             else if (Collection.class.isAssignableFrom(toType)) {
   7:                 return canCreateCollection(toType);
   8:         ...
   9:         }
  10:         else if (object instanceof Collection) {
  11:             if (toType.isArray()) {
  12:         ...
  13:                 Collection collection = allocateCollection(toType);
  14:                 collection.addAll((Collection) object);

View Full Code Here

clear

public void clear()
Removes all of the elements from this collection (optional operation). This collection will be empty after this method returns unless it throws an exception.
Throws:
UnsupportedOperationException - if the clear method is not supported by this collection.
Usages and Demos :

View More Examples of clear()
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:    
   6:    Collection objects;
   7:    
   8:         ...
   9:    
  10:    public void setObjects(Collection newObjects) {
  11:         ...
  12:       objects.clear();

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:     protected String id;
   6:     protected Collection mutableComponentsMetadata;
   7:         ...
   8:     protected Collection systemComponentsMetadata;
   9:     protected Collection linksMetadata;
  10:         ...
  11:     public void setMutableComponentsMetadata(Collection meta) {
  12:         mutableComponentsMetadata.clear();

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: 
   4:         ...
   5:             throws FinderException {
   6:         Collection toDelete = descriptionHome.findByTable_Row(table, 
   7:                 foreignId);
   8:                 
   9:     }

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5: 
   6:         Collection files = new ArrayList();
   7:         for (int i = 0; i < getCommandLine().getPathCount(); i++) {
   8:         ...
   9:         }
  10:         files.clear();
  11:         

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:         
   6:         Collection files = new ArrayList();
   7:         for (int i = 0; i < getCommandLine().getPathCount(); i++) {
   8:         ...
   9:         }
  10:         files.clear();
  11:         

View Full Code Here

contains

public boolean contains(Object o)
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
Parameters:
o - element whose presence in this collection is to be tested.
Returns:
true if this collection contains the specified element
Throws:
ClassCastException - if the type of the specified element is incompatible with this collection (optional).
NullPointerException - if the specified element is null and this collection does not support null elements (optional).
Usages and Demos :

View More Examples of contains(Object o)
   1: 
   2: import java.util.Collection;
   3: 
   4:         ...
   5: 
   6: protected  Collection set;
   7: 
   8:         ...
   9:   }
  10: abstract protected Collection createCollection();
  11: 
  12:         ...
  13:   {
  14:      return set.contains(((Dobject)object).getData());

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.io.File;
   4:         ...
   5:                                implements CollectionOp {
   6: protected  Collection set;
   7: 
   8:         ...
   9:   }
  10: abstract protected Collection createCollection();
  11: 
  12:         ...
  13:   {
  14:      return set.contains(((Dobject)object).getData());

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:     private String userID;
   6:     private Collection roles = new ArrayList();
   7:     private int hash;
   8:         ...
   9:     
  10:     public DCMUser( String userID, Collection roles ) {
  11:         if ( userID == null ) {
  12:         ...
  13:     public void addRole( String role ) {
  14:         if ( ! roles.contains(role ) ) {

View Full Code Here
   1:                  community.hasEntity(AGENT+i));
   2:       Collection parents =
   3:           commSvc[i].listParentCommunities(AGENT+i, (CommunityResponseListener)null);
   4:         ...
   5:                  parents.size() == 1 &&
   6:                  parents.contains(COMMUNITY));
   7:     }
   8:         ...
   9:                  !community.hasEntity(AGENT+i));
  10:       Collection parents =
  11:           commSvc[i].listParentCommunities(AGENT+i, (CommunityResponseListener)null);

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.io.File;
   4:         ...
   5:                                implements CollectionOp {
   6: private  Collection set;
   7: 
   8:         ...
   9:   }
  10: abstract protected Collection createCollection();
  11: 
  12:         ...
  13:   {
  14:      return set.contains(((Dobject)object).getData());

View Full Code Here

containsAll

public boolean containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection.
Parameters:
c - collection to be checked for containment in this collection.
Returns:
true if this collection contains all of the elements in the specified collection
Throws:
ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection (optional).
NullPointerException - if the specified collection contains one or more null elements and this collection does not support null elements (optional).
NullPointerException - if the specified collection is null.
Usages and Demos :

View More Examples of containsAll(Collection c)
   1: 
   2: public class CollectionAdapter implements Collection, Set {
   3:         ...
   4:     Collection collection;
   5:     AbstractAdapter adapter;
   6:         ...
   7:     public boolean containsAll(Collection c) {
   8:     return collection.containsAll(convertCollection2Data(c));
   9:     }

View Full Code Here
   1: import java.io.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9: 
  10:     public SynchronizedCollection(Collection c) {
  11:         if (c==null)
  12:         ...
  13:     public final boolean containsAll(Collection coll) {
  14:         synchronized(mutex) {return c.containsAll(coll);}

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: public class CollectionDelegate
   6:   implements Collection
   7: {
   8:         ...
   9:   protected Collection inner;
  10: 
  11:         ...
  12:   public boolean contains(Object o) { return inner.contains(o); }
  13:   public boolean containsAll(Collection c) { return inner.containsAll(c); }

View Full Code Here
   1: import edu.emory.mathcs.backport.java.util.concurrent.locks.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SCollection implements Collection {
   7:         ...
   8:     private final Collection c;
   9:     private final ReentrantLock l = new ReentrantLock();
  10:         ...
  11:     public final boolean containsAll(Collection coll) {
  12:         l.lock(); try  {return c.containsAll(coll);} finally { l.unlock(); }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public class ReadOnlyCollection implements Collection {
   7:         ...
   8:   private Collection inner;
   9: 
  10:         ...
  11:   public boolean contains(Object o) { return inner.contains(o); }
  12:   public boolean containsAll(Collection c) { return inner.containsAll(c); }

View Full Code Here

equals

public boolean equals(Object o)
Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementer may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Overrides:
equals in interface Object
Parameters:
o - Object to be compared for equality with this collection.
Returns:
true if the specified object is equal to this collection
Usages and Demos :

View More Examples of equals(Object o)
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: public class CollectionDelegate
   6:   implements Collection
   7: {
   8:         ...
   9:   protected Collection inner;
  10: 
  11:         ...
  12:     if (o instanceof CollectionDelegate) {
  13:       return inner.equals(((CollectionDelegate)o).inner);

View Full Code Here
   1: import edu.emory.mathcs.backport.java.util.concurrent.locks.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SCollection implements Collection {
   7:         ...
   8:     private final Collection c;
   9:     private final ReentrantLock l = new ReentrantLock();
  10:         ...
  11:     public final boolean equals(Object o) {
  12:         l.lock(); try {return c.equals(o);} finally { l.unlock(); }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public class ReadOnlyCollection implements Collection {
   7:         ...
   8:   private Collection inner;
   9: 
  10:         ...
  11:   }
  12:   public boolean equals(Object o) { return inner.equals(o); }

View Full Code Here
   1: {
   2:     static Collection synchronizedCollection(Collection c, Object mutex) {
   3:     return new SynchronizedCollection(c, mutex);
   4:         ...
   5: 
   6:     static class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9:     public boolean equals(Object o) {
  10:         synchronized(mutex) {return c.equals(o);}
  11:         }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public class JDOResultCollection implements Collection
   7: {
   8:         ...
   9:     Query q;
  10:     Collection queryresult;
  11:     HashSet iterators;
  12:         ...
  13:     public boolean equals(Object o) {
  14:         return queryresult.equals(o);

View Full Code Here

hashCode

public int hashCode()
Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCodemethod. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().
Overrides:
hashCode in interface Object
Returns:
the hash code value for this collection
Usages and Demos :

View More Examples of hashCode()
   1: import edu.emory.mathcs.backport.java.util.concurrent.locks.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SCollection implements Collection {
   7:         ...
   8:     private final Collection c;
   9:     private final ReentrantLock l = new ReentrantLock();
  10:         ...
  11:     public final int hashCode() {
  12:         l.lock(); try {return c.hashCode();} finally { l.unlock(); }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public class ReadOnlyCollection implements Collection {
   7:         ...
   8:   private Collection inner;
   9: 
  10:         ...
  11:   public boolean equals(Object o) { return inner.equals(o); }
  12:   public int hashCode() { return inner.hashCode(); }

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: import java.util.Collections;
   4:         ...
   5:         super(
   6:             name, Collection.class, identified, isAbstract, restrictions, 
   7:             superType, description
   8:         ...
   9:             try {
  10:                 SCHEMA = (Collection) PROPERTIES.getClass().newInstance();
  11:                 ASSOCIATIONS = (Collection) PROPERTIES.getClass().newInstance();
  12:         ...
  13:     public int hashCode(){
  14:         return super.hashCode() * SCHEMA.hashCode();

View Full Code Here
   1: {
   2:     static Collection synchronizedCollection(Collection c, Object mutex) {
   3:     return new SynchronizedCollection(c, mutex);
   4:         ...
   5: 
   6:     static class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9:     public int hashCode() {
  10:         synchronized(mutex) {return c.hashCode();}
  11:         }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public class JDOResultCollection implements Collection
   7: {
   8:         ...
   9:     Query q;
  10:     Collection queryresult;
  11:     HashSet iterators;
  12:         ...
  13:     public int hashCode() {
  14:         return queryresult.hashCode();

View Full Code Here

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.
Returns:
true if this collection contains no elements
Usages and Demos :

View More Examples of isEmpty()
   1: 
   2: package org.springmodules.validation.util.condition.collection;
   3: 
   4:         ...
   5: import java.lang.reflect.Array;
   6: import java.util.Collection;
   7: 
   8:         ...
   9: 
  10:     protected boolean checkCollection(Collection collection) {
  11:         ...
  12:         return collection.isEmpty();

View Full Code Here
   1:   public static void main(String[] args) {
   2:     Collection c = new ArrayList();
   3:     Collections2.fill(c, 
   4:         ...
   5:       Collections.min(c));
   6:     Collection c2 = new ArrayList();
   7:     Collections2.fill(c2, 
   8:         ...
   9:       "c.containsAll(c2) = "+ c.containsAll(c2));
  10:     Collection c3 = ((List)c).subList(3, 5);
  11:     c2.retainAll(c3);
  12:         ...
  13:     c2.removeAll(c3);
  14:     System.out.println("c.isEmpty() = " +

View Full Code Here
   1: 
   2: public class CollectionAdapter implements Collection, Set {
   3:         ...
   4:     Collection collection;
   5:     AbstractAdapter adapter;
   6:         ...
   7:     public boolean isEmpty() {
   8:     return collection.isEmpty();
   9:     }

View Full Code Here
   1: import java.io.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9: 
  10:     public SynchronizedCollection(Collection c) {
  11:         if (c==null)
  12:         ...
  13:     public final boolean isEmpty() {
  14:         synchronized(mutex) {return c.isEmpty();}

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: public class CollectionDelegate
   6:   implements Collection
   7: {
   8:         ...
   9:   protected Collection inner;
  10: 
  11:         ...
  12:   public boolean containsAll(Collection c) { return inner.containsAll(c); }
  13:   public boolean isEmpty() { return inner.isEmpty(); }

View Full Code Here

iterator

public Iterator iterator()
Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).
Specified by:
iterator in interface Iterable<T>
Returns:
an Iterator over the elements in this collection
Usages and Demos :

View More Examples of iterator()
   1: 
   2: import java.util.Collection;
   3: import java.util.Enumeration;
   4:         ...
   5:   public Enumerator(Iterator i) { this.i = i; }
   6:   public Enumerator(Collection c) { this.i = c.iterator(); }
   7:   public final boolean hasMoreElements() { return i.hasNext(); }
   8:   public final Object nextElement() { return i.next(); }
   9: }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import junit.framework.TestCase;
   4:         ...
   5: 
   6:         final Collection collection = id.toPlugins();
   7:         assertEquals( "plugins.length", 1, collection.size() );
   8:         ...
   9:                       element,
  10:                       collection.iterator().next() );
  11:     }

View Full Code Here
   1: import java.io.StringReader;
   2: import java.util.Collection;
   3: import java.util.Enumeration;
   4:         ...
   5:   protected void aggregatePartiallyCorrelated(boolean timeIncluded,
   6:                                               Collection expandedAtoms,
   7:                                               List output)
   8:         ...
   9:       Object orgString = ((ResultSetDataAtom)
  10:         expandedAtoms.iterator().next()).getIdentifier("cluster");
  11:       DataAtomUtilities.addIdentifier(orgAggregation, "Org", orgString);
  12:         ...
  13:         members = convertToStringVector(members);
  14:         Collection orgAtoms =

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import junit.framework.TestCase;
   4:         ...
   5:         set.addFilter( element );
   6:         final Collection collection = set.toPlugins();
   7:         assertEquals( "collection.size()", 1, collection.size() );
   8:         ...
   9:                       element,
  10:                       collection.iterator().next() );
  11:     }
  12:         ...
  13:                       element,
  14:                       collection.iterator().next() );

View Full Code Here
   1: import java.awt.event.ActionEvent;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5:                 Object receiver = Model.getFacade().getReceiver(obj);
   6:                 Collection c =
   7:                     receiver != null
   8:         ...
   9:                 Object cls =
  10:                     c != null && !c.isEmpty() ? c.iterator().next() : null;
  11:                 if (cls != null && Model.getFacade().isAClassifier(cls)) {
  12:         ...
  13:                     c = Model.getCoreHelper().getOperationsInh(cls);
  14:                     Iterator iter = c != null ? c.iterator() : null;

View Full Code Here

remove

public boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if this collection changed as a result of the call
Throws:
ClassCastException - if the type of the specified element is incompatible with this collection (optional).
NullPointerException - if the specified element is null and this collection does not support null elements (optional).
UnsupportedOperationException - remove is not supported by this collection.
Usages and Demos :

View More Examples of remove(Object o)
   1:   public static void main(String[] args) {
   2:     Collection c = new ArrayList();
   3:     Collections2.fill(c, 
   4:         ...
   5:       Collections.min(c));
   6:     Collection c2 = new ArrayList();
   7:     Collections2.fill(c2, 
   8:         ...
   9:     System.out.println(c);
  10:     c.remove(CountryCapitals.pairs[0][0]);
  11:     System.out.println(c);
  12:         ...
  13:     c.remove(CountryCapitals.pairs[1][0]);

View Full Code Here
   1: public class Collection1 {
   2:   public static Collection 
   3:         ...
   4:   fill(Collection c, int start, int size) {
   5:     for(int i = start; i < start + size; i++)
   6:         ...
   7:   }
   8:   public static Collection 
   9:   fill(Collection c, int size) {

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: import java.util.Date;
   4:         ...
   5:         try {
   6:             decoratedMap.remove(stringProp.getName());
   7:             fail("decoratedMap.remove()");
   8:         ...
   9:         try {
  10:             modifiableMap.remove(stringProp.getName());
  11:             fail("modifiableMap.remove()");
  12:         ...
  13:     public void testValues() {
  14:         Collection collection = modifiableMap.values();

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: import java.util.HashMap;
   4:         ...
   5:         Set keySet = null;
   6:         Collection all = new ArrayList();
   7: 
   8:         ...
   9: 
  10:         all.remove("bar");
  11:         keySet = context.keySet();
  12:         ...
  13: 
  14:         keySet.remove("baz");

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: import java.util.HashMap;
   4:         ...
   5: 
   6:         context.remove("bar");
   7:         checkAttributeCount(2);
   8:         ...
   9:         assertTrue(context.containsValue("bop value"));
  10:         context.remove("bop");
  11:         assertTrue(!context.containsKey("bop"));
  12:         ...
  13:         Set keySet = null;
  14:         Collection all = new ArrayList();

View Full Code Here

removeAll

public boolean removeAll(Collection c)
Removes all this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call
Throws:
UnsupportedOperationException - if the removeAll method is not supported by this collection.
ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional).
NullPointerException - if this collection contains one or more null elements and the specified collection does not support null elements (optional).
NullPointerException - if the specified collection is null.
Usages and Demos :

View More Examples of removeAll(Collection c)
   1:   public static void main(String[] args) {
   2:     Collection c = new ArrayList();
   3:     Collections2.fill(c, 
   4:         ...
   5:       Collections.min(c));
   6:     Collection c2 = new ArrayList();
   7:     Collections2.fill(c2, 
   8:         ...
   9:     System.out.println(c);
  10:     c.removeAll(c2);
  11:     System.out.println(c);
  12:         ...
  13:       "c.containsAll(c2) = "+ c.containsAll(c2));
  14:     Collection c3 = ((List)c).subList(3, 5);

View Full Code Here
   1: 
   2: public class CollectionAdapter implements Collection, Set {
   3:         ...
   4:     Collection collection;
   5:     AbstractAdapter adapter;
   6:         ...
   7:     public boolean removeAll(Collection c) {
   8:     return collection.removeAll(convertCollection2Data(c));
   9:     }

View Full Code Here
   1: import java.io.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9: 
  10:     public SynchronizedCollection(Collection c) {
  11:         if (c==null)
  12:         ...
  13:     public final boolean removeAll(Collection coll) {
  14:         synchronized(mutex) {return c.removeAll(coll);}

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: public class CollectionDelegate
   6:   implements Collection
   7: {
   8:         ...
   9:   protected Collection inner;
  10: 
  11:         ...
  12:   public boolean remove(Object o) { return inner.remove(o); }
  13:   public boolean removeAll(Collection c) { return inner.removeAll(c); }

View Full Code Here
   1: import edu.emory.mathcs.backport.java.util.concurrent.locks.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SCollection implements Collection {
   7:         ...
   8:     private final Collection c;
   9:     private final ReentrantLock l = new ReentrantLock();
  10:         ...
  11:     public final boolean removeAll(Collection coll) {
  12:         l.lock(); try  {return c.removeAll(coll);} finally { l.unlock(); }

View Full Code Here

retainAll

public boolean retainAll(Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call
Throws:
UnsupportedOperationException - if the retainAll method is not supported by this Collection.
ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional).
NullPointerException - if this collection contains one or more null elements and the specified collection does not support null elements (optional).
NullPointerException - if the specified collection is null.
Usages and Demos :

View More Examples of retainAll(Collection c)
   1: 
   2: public class CollectionAdapter implements Collection, Set {
   3:         ...
   4:     Collection collection;
   5:     AbstractAdapter adapter;
   6:         ...
   7:     public boolean retainAll(Collection c) {
   8:     return collection.retainAll(convertCollection2Data(c));
   9:     }

View Full Code Here
   1: import java.io.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9: 
  10:     public SynchronizedCollection(Collection c) {
  11:         if (c==null)
  12:         ...
  13:     public final boolean retainAll(Collection coll) {
  14:         synchronized(mutex) {return c.retainAll(coll);}

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: public class CollectionDelegate
   6:   implements Collection
   7: {
   8:         ...
   9:   protected Collection inner;
  10: 
  11:         ...
  12:   public boolean removeAll(Collection c) { return inner.removeAll(c); }
  13:   public boolean retainAll(Collection c) { return inner.retainAll(c); }

View Full Code Here
   1: import edu.emory.mathcs.backport.java.util.concurrent.locks.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SCollection implements Collection {
   7:         ...
   8:     private final Collection c;
   9:     private final ReentrantLock l = new ReentrantLock();
  10:         ...
  11:     public final boolean retainAll(Collection coll) {
  12:         l.lock(); try  {return c.retainAll(coll);} finally { l.unlock(); }

View Full Code Here
   1: public class Collection1 {
   2:   public static Collection 
   3:         ...
   4:   fill(Collection c, int start, int size) {
   5:     for(int i = start; i < start + size; i++)
   6:         ...
   7:   }
   8:   public static Collection 
   9:   fill(Collection c, int size) {
  10:         ...
  11:     Collection c2 = newCollection(5, 3);
  12:     c.retainAll(c2);

View Full Code Here

size

public int size()
Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Returns:
the number of elements in this collection
Usages and Demos :

View More Examples of size()
   1: import java.net.URL;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:         NamespaceComponents.instance().discover();
   6:         Collection profiles = ComponentContainer.instance().findComponentsOfType(Profile.class);
   7:         assertNotNull(profiles);
   8:         ...
   9:             1,
  10:             profiles.size());
  11:         Profile profile = (Profile)profiles.iterator().next();

View Full Code Here
   1: import java.net.URL;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:     assertTrue("Expect decorator is found", decorator != null) ;
   6:     Collection list = service_.getPageDecorators();
   7:         ...
   8:     assertEquals("Expect 1 decorator in the list", 1, list.size()) ;
   9: 
  10:         ...
  11:     list = service_.getContainerDecorators();
  12:     assertEquals("Expect 3 decorators in the list", 3, list.size()) ;

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.Collection;
   3: 
   4:         ...
   5:    private Object writeOwner_;
   6:    private Collection readOwnerList_;
   7: 
   8:         ...
   9:             if ((writeOwner_ != null && writeOwner_.equals(owner) ||
  10:                readOwnerList_.size() != 0 && readOwnerList_.contains(owner)))
  11:                hasOwner = true;
  12:         ...
  13:          case OWNER_READ:
  14:             if (readOwnerList_.size() != 0 && readOwnerList_.contains(owner))

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.HashMap;
   4:         ...
   5:         {
   6:             Collection values = (Collection)i.next();
   7:             
   8:         ...
   9:             Collection values = (Collection)i.next();
  10:             count += values.size();
  11:         }

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Date;
   4:         ...
   5:     public void testGetVets() {
   6:         Collection vets = this.clinic.getVets();
   7:         
   8:         ...
   9:                 jdbcTemplate.queryForInt("SELECT COUNT(0) FROM VETS"), 
  10:                 vets.size());
  11:         Vet v1 = (Vet) EntityUtils.getById(vets, Vet.class, 2);
  12:         ...
  13:     public void testGetPetTypes() {
  14:         Collection petTypes = this.clinic.getPetTypes();

View Full Code Here

toArray

public Object[] toArray()
Returns an array containing all of the elements in this collection. If the collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Returns:
an array containing all of the elements in this collection
Usages and Demos :

View More Examples of toArray()
   1: 
   2: import java.util.Collection;
   3: 
   4:         ...
   5:     public static Object getSelection(IGUISeSAmDeclaration guiSeSAmDeclaration,
   6:             String title, Object message, Collection options, Object _default) 
   7:     {        
   8:         ...
   9:                 null,
  10:                 options.toArray(),
  11:                 _default);

View Full Code Here
   1: import java.beans.PropertyDescriptor;
   2: import java.util.Collection;
   3: 
   4:         ...
   5: 
   6:     public void setChoices(Collection choices) {
   7:         ...
   8:         comboBox.setModel(new DefaultComboBoxModel(choices.toArray()));
   9:     }

View Full Code Here
   1: import java.io.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SynchronizedCollection implements Collection, Serializable {
   7:     private static final long serialVersionUID = 3053995032091335093L;
   8:         ...
   9: 
  10:     public SynchronizedCollection(Collection c) {
  11:         if (c==null)
  12:         ...
  13:     public final Object[] toArray() {
  14:         synchronized(mutex) {return c.toArray();}

View Full Code Here
   1: 
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: public class CollectionDelegate
   6:   implements Collection
   7: {
   8:         ...
   9:   protected Collection inner;
  10: 
  11:         ...
  12:   public int size() { return inner.size(); }
  13:   public Object[] toArray() { return inner.toArray(); }

View Full Code Here
   1: import edu.emory.mathcs.backport.java.util.concurrent.locks.*;
   2: import java.util.Collection;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6: public final class SCollection implements Collection {
   7:         ...
   8:     private final Collection c;
   9:     private final ReentrantLock l = new ReentrantLock();
  10:         ...
  11:     public final Object[] toArray() {
  12:         l.lock(); try  {return c.toArray();} finally { l.unlock(); }

View Full Code Here