分享
 
 
 

java.util.Set翻译

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

[/url] [url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

JavaTM 2 Platform

Std. Ed. v1.4.2

PREV CLASS NEXT CLASS

FRAMES NO FRAMES All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

java.util

Interface SetAll Superinterfaces: Collection All Known Subinterfaces: SortedSet All Known Implementing Classes: AbstractSet, HashSet, LinkedHashSet, TreeSet public interface Set extends CollectionA collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction. 不包含重复元素的集合。更正式地讲,set中不存在那样的一对元素,e1和e2,使得e1.equals(e2),至多也只能有一个null元素。和它名称暗示的一样,接口模拟了数学中的set概念。

The Set interface places additional stipulations, beyond those inherited from the Collection interface, on the contracts of all constructors and on the contracts of the add, equals and hashCode methods. Declarations for other inherited methods are also included here for convenience. (The specifications accompanying these declarations have been tailored to the Set interface, but they do not contain any additional stipulations.) Set接口除了继承自Collection接口,遵守所有构造函数、add、equals和hashCode方法的约定之外, 还有一些额外约定。其他继承方法的声明为了简便起见,也包括在此。 (和这些声明相关的规定在Set接口中已有修正,但是它们不包括任何额外的约定。)

The additional stipulation on constructors is, not surprisingly, that all constructors must create a set that contains no duplicate elements (as defined above). 构造函数的额外约定并不新鲜,它要求所有构造函数必须创建一个不包含重复元素的set(根据以上定义)。

Note: Great care must be exercised if mutable objects are used as set elements. The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set. A special case of this prohibition is that it is not permissible for a set to contain itself as an element. 注意:如果set元素为可变对象,应该引起足够注意。如果某个对象的值以某种方法改变,而该对象是set中的一个元素,影响了equals比较,那么set的行为无法确定。

Some set 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 set 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. 某些set的实现对于它所包含的元素有限制。例如,某些实现禁止null元素,某些元素的类型受限制。试图加入一个不适当的元素会抛出未检查异常,通常为NullPointerException或ClassCastException。试图查询一个不适当的元素是否存在也可能抛出异常,或者简单返回false。某些实现显示前者,某些显示后者。更一般而言,试图对一个不适当的元素进行操作会造成不适当元素向set的插入,根据option实现的不同,可能抛出异常,也可能成功。那些异常在该接口的规范中标记为“optional(可选)”。

This interface is a member of the Java Collections Framework. 该接口是Java集合框架成员之一。

Since: 1.2 See Also: Collection, List, SortedSet, HashSet, TreeSet, AbstractSet, Collections.singleton(java.lang.Object), Collections.EMPTY_SETMethod Summary

boolean

add(Object o)

Adds the specified element to this set if it is not already present (optional operation). 如果set中不存在指定元素,则向set加入(可选操作)。

boolean

addAll(Collection c)

Adds all of the elements in the specified collection to this set if they're not already present (optional operation). 如果set中中不存在指定集合的元素,则向set中加入所有元素(可选操作)。

void

clear()

Removes all of the elements from this set (optional operation). 从set中删除所有元素(可选操作)。

boolean

contains(Object o)

Returns true if this set contains the specified element. 如果set包含指定元素,返回true。

boolean

containsAll(Collection c)

Returns true if this set contains all of the elements of the specified collection. 如果set包含指定集合的所有元素,返回true。

boolean

equals(Object o)

Compares the specified object with this set for equality. 将指定对象和当前set就相等性进行比较。

int

hashCode()

Returns the hash code value for this set. 返回set的哈希码值。

boolean

isEmpty()

Returns true if this set contains no elements. 如果set中不含元素,返回true。

Iterator

iterator()

Returns an iterator over the elements in this set. 返回set中元素的迭代器。

boolean

remove(Object o)

Removes the specified element from this set if it is present (optional operation). 如果set中存在指定元素,则从set中删除(可选操作)。

boolean

removeAll(Collection c)

Removes from this set all of its elements that are contained in the specified collection (optional operation). 如果set包含指定集合,则从set中删除指定集合的所有元素(可选操作)。

boolean

retainAll(Collection c)

Retains only the elements in this set that are contained in the specified collection (optional operation). 只保留set中所含的指定集合的元素(可选操作)。

int

size()

Returns the number of elements in this set (its cardinality). 返回set中元素的数目。

Object[]

toArray()

Returns an array containing all of the elements in this set. 返回包含set中所有元素的数组。

Object[]

)]toArray(Object[] a)

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. 返回包含set中所有元素的数组,返回数组的运行时类型是指定数组的运行时类型。

Method Detail

sizepublic int size()

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. 返回set中元素的数目。如果set包含的元素数大于Integer.MAX_VALUE,返回Integer.MAX_VALUE。

Specified by: size in interface CollectionReturns: the number of elements in this set (its cardinality). set中元素的数目。isEmptypublic boolean isEmpty()

Returns true if this set contains no elements. 如果set中不含元素,返回true。

Specified by: isEmpty in interface CollectionReturns: true if this set contains no elements. 如果set中不含元素,返回true。containspublic boolean contains(Object o)

Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). 如果set包含指定元素,返回true。更正式地讲,只有当set包含元素e,使得(o==null ? e==null : o.equals(e)),才返回true。

Specified by: contains in interface CollectionParameters: o - element whose presence in this set is to be tested. 元素,用来测试是否存在于set中。 Returns: true if this set contains the specified element. 如果set包含指定元素,返回true。 Throws: ClassCastException - if the type of the specified element is incompatible with this set (optional). 如果指定元素的类型和set中的不匹配,则抛出(可选)。 NullPointerException - if the specified element is null and this set does not support null elements (optional). 如果指定元素为null,而set不支持null元素,则抛出(可选)。iteratorpublic Iterator iterator()

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). 返回set中元素的迭代器。元素返回没有特定的顺序,除非set是提高了该保证的某些类的实例。

Specified by: iterator in interface CollectionReturns: an iterator over the elements in this set. set中元素的迭代器。toArraypublic Object[] toArray()

Returns an array containing all of the elements in this set. Obeys the general contract of the Collection.toArray method. 返回包含set中所有元素的数组。遵守Collection.toArray方法的一般约定。

Specified by: toArray in interface CollectionReturns: an array containing all of the elements in this set. 包含set中所有元素的数组。toArraypublic Object[] toArray(Object[] a)

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. Obeys the general contract of the Collection.toArray(Object[]) method. 返回包含set中所有元素的数组,返回数组的运行时类型是指定数组的运行时类型。

Specified by: )]toArray in interface CollectionParameters: a - the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose. set中元素要被存储的数组,如果它足够大;否则,为此构建一个运行时类型相同的新的数组。 Returns: an array containing the elements of this set. 包含set中所有元素的数组。 Throws: ArrayStoreException - the runtime type of a is not a supertype of the runtime type of every element in this set. 如果a的运行时类型不是set中每个元素运行时类型的父一级类型时抛出。 NullPointerException - if the specified array is null. 如果指定数组为null时抛出。addpublic boolean add(Object o)

Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element, o, to this set if this set contains no element e such that (o==null ? e==null : o.equals(e)). If this set already contains the specified element, the call leaves this set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements. 如果set中不存在指定元素,则向set加入(可选操作)。更正式地讲,如果set不含这样的 元素e,使得(o==null ? e==null : o.equals(e)),那么向set加入指定元素o。 如果set已经包含了指定元素,调用不改变set,返回false。 构造函数中的限制,将确保set不会包含重复元素。 The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throwing an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the the elements that they may contain. 以上的规定并不意味着set可以接受所有元素,set可能拒绝加入某个特定元素,包括 null,抛出异常,和规范中Collection.add的描述一样。特殊的set实现应当在文档中 明确set可以包含元素的限制。

Specified by: add in interface CollectionParameters: o - element to be added to this set. 要加入set的元素。 Returns: true if this set did not already contain the specified element. 如果set中还未包含指定元素,返回true。 Throws: UnsupportedOperationException - if the add method is not supported by this set. 如果当前set不支持add方法时抛出。 ClassCastException - if the class of the specified element prevents it from being added to this set. 如果指定集合的某些元素类型阻止其加入set时抛出。 NullPointerException - if the specified element is null and this set does not support null elements. 如果指定元素为null而set不支持null元素时抛出。 IllegalArgumentException - if some aspect of the specified element prevents it from being added to this set. 如果指定元素的某些方面不允许它加入当前set则抛出。removepublic boolean remove(Object o)

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the set contains such an element. Returns true if the set contained the specified element (or equivalently, if the set changed as a result of the call). (The set will not contain the specified element once the call returns.) 如果set中存在指定元素,则从set中删除(可选操作)。更正式地讲,如果set中含有那样一个元素e, 使得(o==null ? e==null : o.equals(e)),那么删除元素e。如果set包含指定元素,返回true( 也可以说,调用的结果使得set发生改变)。一旦set不含指定元素,调用返回。

Specified by: remove in interface CollectionParameters: o - object to be removed from this set, if present. 要从set中删除的对象(若有)。 Returns: true if the set contained the specified element. 如果set中存在指定元素,返回true。 Throws: ClassCastException - if the type of the specified element is incompatible with this set (optional). 如果指定元素的类型和当前set中的不匹配,则抛出(可选)。 NullPointerException - if the specified element is null and this set does not support null elements (optional). 如果指定元素为null而set不支持null元素时抛出(可选)。 UnsupportedOperationException - if the remove method is not supported by this set. 如果当前set不支持remove方法则抛出。containsAllpublic boolean containsAll(Collection c)

Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set. 如果set包含指定集合的所有元素,返回true。如果指定集合也是一个set,只有是当前set的子集时,方法返回true。

Specified by: containsAll in interface CollectionParameters: c - collection to be checked for containment in this set. 检查set包容性的集合。 Returns: true if this set contains all of the elements of the specified collection. 如果set包含指定集合的所有元素,返回true。 Throws: ClassCastException - if the types of one or more elements in the specified collection are incompatible with this set (optional). 如果指定集合的一个或多个元素的类型和set中的不匹配,则抛出(可选)。 NullPointerException - if the specified collection contains one or more null elements and this set does not support null elements (optional). 如果指定集合中包含一个或多个null元素,而set不支持null元素则抛出(可选)。 NullPointerException - if the specified collection is null. 如果指定集合为null抛出。 See Also: contains(Object)addAllpublic boolean addAll(Collection c)

Adds all of the elements in the specified collection to this set if they're not already present (optional operation). If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. 如果set中中不存在指定集合的元素,则向set中加入所有元素(可选操作)。 如果指定集合也是一个set,那么addAll操作修改set的效果是使它的值为两个set的并集。 如果操作进行中指定集合被修改,那么该操作的行为无法确定。

Specified by: addAll in interface CollectionParameters: c - collection whose elements are to be added to this set. 要将其元素加入set的集合。 Returns: true if this set changed as a result of the call. 如果调用的结果改变了set,返回true。 Throws: UnsupportedOperationException - if the addAll method is not supported by this set. 如果当前set不支持addAll方法抛出。 ClassCastException - if the class of some element of the specified collection prevents it from being added to this set. 如果指定集合的某些元素类型阻止其加入set时抛出。 NullPointerException - if the specified collection contains one or more null elements and this set does not support null elements, or if the specified collection is null. 如果指定集合包含一个或多个null元素而当前set不支持null元素,或者指定集合为null抛出。 IllegalArgumentException - if some aspect of some element of the specified collection prevents it from being added to this set. 如果指定集合的某些元素的某些方面不允许它加入当前set则抛出。 See Also: add(Object)retainAllpublic boolean retainAll(Collection c)

Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets. 只保留set中所含的指定集合的元素(可选操作)。换言之,从set中删除所有指定集合不包含的元素。 如果指定集合也是一个set,那么该操作修改set的效果是使它的值为两个set的交集。

Specified by: retainAll in interface CollectionParameters: c - collection that defines which elements this set will retain. 定义set将保留元素的集合。 Returns: true if this collection changed as a result of the call. 如果调用的结果改变了集合,返回true。 Throws: UnsupportedOperationException - if the retainAll method is not supported by this Collection. 如果当前Collection不支持retainAll方法时抛出。 ClassCastException - if the types of one or more elements in this set are incompatible with the specified collection (optional). 如果当前set的一个或多个元素的类型和指定集合中的不匹配,则抛出(可选)。 NullPointerException - if this set contains a null element and the specified collection does not support null elements (optional). 如果当前set包含一个或多个null元素,而指定集合不支持null元素则抛出(可选)。 NullPointerException - if the specified collection is null. 如果指定集合为null抛出。 See Also: remove(Object)removeAllpublic boolean removeAll(Collection c)

Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets. 如果set包含指定集合,则从set中删除指定集合的所有元素(可选操作)。 如果指定集合也是一个set,那么该操作修改set的效果是使它的值为两个set的(不对称)差集。

Specified by: removeAll in interface CollectionParameters: c - collection that defines which elements will be removed from this set. 集合,定义为从set中删除它的元素。 Returns: true if this set changed as a result of the call. 如果调用的结果改变了set,返回true。 Throws: UnsupportedOperationException - if the removeAll method is not supported by this Collection. 如果当前Collection不支持removeAll方法时抛出。 ClassCastException - if the types of one or more elements in this set are incompatible with the specified collection (optional). 如果当前set的一个或多个元素的类型和指定集合中的不匹配,则抛出(可选)。 NullPointerException - if this set contains a null element and the specified collection does not support null elements (optional). 如果当前set包含一个或多个null元素,而指定集合不支持null元素则抛出(可选)。 NullPointerException - if the specified collection is null. 如果指定集合为null时抛出。 See Also: remove(Object)clearpublic void clear()

Removes all of the elements from this set (optional operation). This set will be empty after this call returns (unless it throws an exception). 从set中删除所有元素(可选操作)。在调用返回后set将为空(除非抛出异常)。

Specified by: clear in interface CollectionThrows: UnsupportedOperationException - if the clear method is not supported by this set. 如果当前set不支持clear方法,则抛出。equalspublic boolean equals(Object o)

Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface. 将指定对象和当前set就相等性进行比较。如果指定对象也是一个set,两个set有着相同大小,指定set的每一个成员在当前 set中(也可以说当前set的每一个成员包含在指定set中)。该定义可以 保证对于set接口的不同实现,equals方法都能正常工作。

Specified by: equals in interface Collection Overrides: equals in class ObjectParameters: o - Object to be compared for equality with this set. 同当前set比较相等性的Object。 Returns: true if the specified Object is equal to this set. 如果指定对象和当前set相等,返回true。 See Also: Object.hashCode(), HashtablehashCodepublic int hashCode()

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hashcode of a null element is defined to be zero. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of the Object.hashCode method. 返回set的哈希码值。set的哈希码被定义为set中元素的哈希码之和,这里null元素的哈希码被定义为0。 这将保证对于两个set s1和s2,s1.equals(s2)意味着s1.hashCode()==s2.hashCode(),遵循 Object.hashCode方法的一般约定。

Specified by: hashCode in interface Collection Overrides: hashCode in class ObjectReturns: the hash code value for this set. set的哈希码值。 See Also: Object.hashCode(), Object.equals(Object), equals(Object)[/url][url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

JavaTM 2 Platform

Std. Ed. v1.4.2

PREV CLASS NEXT CLASS

FRAMES NO FRAMES All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature

For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有