Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

Interface: Set

rules.Set

interface   static

Set type.

A set is an unordered collection. A set cannot contain duplicate items.

There is no set literal for use in creating sets. Instead, create sets from lists usingList.toSet(). Seerules.List.

// Create a set and check its size['a','b'].toSet().size()==2

In addition to the methods listed below, sets have the following operators:


OperatorUsage
x == yCompare sets x and y
v in x

Check if value v exists in set x. For example:

'a' in ['a','b'].toSet() == true

Methods

difference

difference() returns rules.Set

Returns a set that is the difference between the set callingdifference() and the set passed todifference(). That is, returns a set containing the elements in the comparison set that are not in the specified set.

If the sets are identical, returns an empty set (size() == 0).

Returns

non-nullrules.Set difference set containing the elements found in the comparison set that are not gound in the calling set.

Example

['a','b'].toSet().difference(['a','c'].toSet()) == ['b'].toSet()

hasAll

hasAll() returns rules.Boolean

Test whether the set callinghasAll() contains all of the items in the comparison set passed tohasAll().

Returns

non-nullrules.Boolean whether the calling set contains all the items of the comparison set or list.

Example

['a','b'].toSet().hasAll(['a','c']) == false['d','e','f'].toSet().hasAll(['d','e']) == true

hasAny

hasAny() returns rules.Boolean

Test whether the set callinghasAny() contains any of the items in the set or list passed tohasAny().

Returns

non-nullrules.Boolean whether the calling set contains any of the items of the comparison set or list.

Example

['a','b'].toSet().hasAny(['c','d'].toSet()) == false['a','b'].toSet().hasAny(['a','c'].toSet()) == true

hasOnly

hasOnly() returns rules.Boolean

Test whether the set callinghasOnly() contains only the items in the comparison set or list passed tohasOnly().

Returns

non-nullrules.Boolean whether the calling set contains only the items of the comparison set or list.

Example

['a','b'].toSet().hasOnly(['a','c']) == false['a','b'].toSet().hasOnly(['a','b']) == true

intersection

intersection() returns rules.Set

Returns a set that is the intersection between the set callingintersection() and the set passed tointersection(). That is, returns a set containing the elements the sets have in common.

If the sets have no elements in common, returns an empty set (size() == 0).

Returns

non-nullrules.Set intersection set containing the elements found in both the calling set and the comparison set.

Example

['a','b'].toSet().intersection(['a','c'].toSet()) == ['a'].toSet()

size

size() returns rules.Integer

Returns the size of the set.

Returns

non-nullrules.Integer the number of values in the specified set.

union

union() returns rules.Set

Returns a set that is the union of the set callingunion() and the set passed tounion(). That is, returns a set that contains all elements from both sets.

Returns

non-nullrules.Set union set containing all of the elements in both the calling set and comparison set.

Example

['a','b'].toSet().union(['a','c'].toSet()) == ['a', 'b', 'c'].toSet()

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-11-14 UTC.


[8]ページ先頭

©2009-2026 Movatter.jp