scala.collection

trait Set

[source: scala/collection/Set.scala]

trait Set[A]
extends (A) => Boolean with Collection[A]

A set is a collection that includes at most one of any object.

This trait provides a limited interface, only allowing reading of elements. There are two extensions of this trait, in packages scala.collection.mutable and scala.collection.immutable, which provide functionality for adding and removing objects from the set. The trait in the first package is for sets that are modified destructively, whereas the trait in the second package is for immutable sets which create a new set when something is added or removed to them.

Author
Matthias Zenger
Martin Odersky
Version
2.0, 01/01/2007
Direct Known Subclasses:
BitSet, SetProxy, SortedSet, Set, Set

Method Summary
def apply (elem : A) : Boolean
This method allows sets to be interpreted as predicates. It returns true, iff this set contains element elem.
abstract def contains (elem : A) : Boolean
Checks if this set contains element elem.
override def equals (that : Any) : Boolean
Compares this set with another object and returns true, iff the other object is also a set which contains the same elements as this set.
override def hashCode : Int
hashcode for this set
override def isEmpty : Boolean
Checks if this set is empty.
abstract def size : Int
Returns the number of elements in this set.
def subsetOf (that : Set[A]) : Boolean
Checks if this set is a subset of set that.
override def toArray [B >: A] : Array[B]
Converts this iterable to a fresh Array with elements.
Methods inherited from Collection
toString, stringPrefix, equalWith
Methods inherited from Iterable
elements (abstract), concat, ++, map, flatMap, filter, takeWhile, dropWhile, take, drop, foreach, forall, exists, find, findIndexOf, indexOf, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, mkString, mkString, addString, addString, copyToArray, projection, hasDefiniteSize
Methods inherited from Function1
compose, andThen
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
abstract def size : Int
Returns the number of elements in this set.
Returns
number of set elements.
Overrides
Collection.size

abstract def contains(elem : A) : Boolean
Checks if this set contains element elem.
Parameters
elem - the element to check for membership.
Returns
true iff elem is contained in this set.

def apply(elem : A) : Boolean
This method allows sets to be interpreted as predicates. It returns true, iff this set contains element elem.
Parameters
elem - the element to check for membership.
Returns
true iff elem is contained in this set.
Overrides
Function1.apply

override def isEmpty : Boolean
Checks if this set is empty.
Returns
true iff there is no element in the set.

def subsetOf(that : Set[A]) : Boolean
Checks if this set is a subset of set that.
Parameters
that - another set.
Returns
true iff the other set is a superset of this set. todo: rename to isSubsetOf

override def equals(that : Any) : Boolean
Compares this set with another object and returns true, iff the other object is also a set which contains the same elements as this set.
Parameters
that - the other object
Returns
true iff this set and the other set contain the same elements.

override def hashCode : Int
hashcode for this set

@deprecated

override def toArray[B >: A] : Array[B]
Converts this iterable to a fresh Array with elements.
Deprecated
This method is broken for BitSet. BitSet.toArray will be updated to new behavior in a future release.
Overrides
Collection.toArray