Code example for Collection

Methods: contains, iterator, size

0
     */ 
    public Pair(Collection<? extends T> values) 
    { 
        if (values == null)
            throw new IllegalArgumentException("Input collection cannot be null");
    	if (values.size() == 2)
        { 
            if(values.contains(null)) 
                throw new IllegalArgumentException("Pair cannot contain null values");
            Iterator<? extends T> iter = values.iterator();
            first = iter.next();
            second = iter.next();
       } 
        else 
            throw new IllegalArgumentException("Pair may only be created from a Collection of exactly 2 elements");
         
    } 
     
    /** 
     * Creates a <code>Pair</code> from the passed array. 
     * The size of the array must be 2.