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 * (that : Set[A]) : Set[A]
def ** (that : Set[A]) : Set[A]
Intersect. It computes an intersection with set that. It removes all the elements that are not present in that.
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
override def isEmpty : Boolean
Checks if this set is empty.
abstract def size : Int
Returns the number of elements in this set.
protected override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation.
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
Methods inherited from Iterable
elements (abstract), concat, ++, map, flatMap, filter, partition, takeWhile, dropWhile, take, drop, foreach, forall, exists, find, findIndexOf, indexOf, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, toSeq, toStream, mkString, 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

@deprecated

def *(that : Set[A]) : Set[A]

def **(that : Set[A]) : Set[A]
Intersect. It computes an intersection with set that. It removes all the elements that are not present in that.
Parameters
that - the set to intersect with

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
Notes
not necessarily run-time type safe.
Returns
true iff this set and the other set contain the same elements.

override def hashCode : Int

override def toArray[B >: A] : Array[B]
Converts this iterable to a fresh Array with elements.
Overrides
Collection.toArray

protected override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation.
Overrides
Collection.stringPrefix