java.util.concurrent.ConcurrentSkipListSet的equals()方法是Java中的一个内置函数,该函数将指定对象与此设置的对象进行相等性比较。如果指定对象也是集合,则返回True。如果满足以下所有条件,则这两个集合将相等。
- 两组尺寸相同。
- 指定集中的每个成员都包含在此集中。
此定义确保equals方法可在set接口的不同实现中正常工作。
用法:
ConcurrentSkipListSet.equals(Object o)
参数:该函数返回单个参数o,即与该集合进行相等性比较的对象
返回值:该函数返回布尔值。如果指定对象等于此集合,则返回true,否则返回false。
以下示例程序旨在说明ConcurrentSkipListSet.equals()方法:
示例1:在此示例中,两个集合相等。
// Java Program Demonstrate equals()
// method of ConcurrentSkipListSet
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetEqualsExample1 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<Integer>
set = new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
set.add(10);
set.add(35);
set.add(20);
set.add(25);
// Creating a descending set object
NavigableSet<Integer> des_set = set.descendingSet();
// Checking if the set and des
if (set.equals(des_set))
System.out.println("Both the sets are equal");
else
System.out.println("Both the sets are not equal");
// Printing the elements of the set
System.out.println("Contents of the set: " + set);
// Printing the elements of the descending set
System.out.println("Contents of the descending set: " +
des_set);
}
}
输出:
Both the sets are equal Contents of the set: [10, 20, 25, 35] Contents of the descending set: [35, 25, 20, 10]
示例2:在此示例中,两个集合不相等
// Java Program Demonstrate equals()
// method of ConcurrentSkipListSet
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetEqualsExample2 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<Integer>
set1 = new ConcurrentSkipListSet<Integer>();
ConcurrentSkipListSet<Integer>
set2 = new ConcurrentSkipListSet<Integer>();
// Adding elements to first set
set1.add(10);
set1.add(35);
set1.add(20);
set1.add(25);
// Adding elements to second set
set2.add(35);
set2.add(20);
set2.add(25);
// Checking if the set and des
if (set1.equals(set2))
System.out.println("Both the sets are equal");
else
System.out.println("Both the sets are not equal");
// Printing the elements of the set
System.out.println("Contents of the first set: " +
set1);
// Printing the elements of the descending set
System.out.println("Contents of the second set: " +
set2);
}
}
输出:
Both the sets are not equal Contents of the first set: [10, 20, 25, 35] Contents of the second set: [20, 25, 35]
相关用法
- Java ConcurrentSkipListSet contains()用法及代码示例
- Java ConcurrentSkipListSet first()用法及代码示例
- Java ConcurrentSkipListSet add()用法及代码示例
- Java ConcurrentSkipListSet last()用法及代码示例
- Java ConcurrentSkipListSet subSet()用法及代码示例
- Java ConcurrentSkipListSet spliterator()用法及代码示例
- Java ConcurrentSkipListSet floor()用法及代码示例
- Java ConcurrentSkipListSet headSet()用法及代码示例
- Java ConcurrentSkipListSet higher()用法及代码示例
- Java ConcurrentSkipListSet pollFirst()用法及代码示例
- Java ConcurrentSkipListSet pollLast()用法及代码示例
- Java ConcurrentSkipListSet removeAll()用法及代码示例
- Java ConcurrentSkipListSet descendingIterator()用法及代码示例
- Java ConcurrentSkipListSet clear()用法及代码示例
- Java ConcurrentSkipListSet size()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 ConcurrentSkipListSet equals() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。