这个 包含() 方法 JAVAutil。同时发生的ConcurrentSkipListSet 是Java中的内置函数,如果指定元素存在于该集合中,则返回true boolean值,否则返回false。
null
语法:
ConcurrentSkipListSet.contains(Object o)
参数: 该函数只接受一个参数 o i、 e.检查该装置中是否存在。
返回值: 该函数返回一个布尔值。如果此集合中存在指定的元素,则返回True,否则返回False。
下面的程序演示了ConcurrentSkipListSet。contains()方法:
项目1:
// Java Program Demonstrate contains() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetContainsExample1 { public static void main(String[] args) { // Initializing the set ConcurrentSkipListSet<Integer> set = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set for ( int i = 10 ; i <= 15 ; i++) set.add(i); // Checks if 9 is present in the set if (set.contains( 9 )) System.out.println( "9 is present in the set." ); else System.out.println( "9 is not present in the set." ); } } |
输出:
9 is not present in the set.
项目2:
// Java Program Demonstrate contains() // method of ConcurrentSkipListSet */ import java.util.concurrent.*; class ConcurrentSkipListSetContainsExample2 { public static void main(String[] args) { // Initializing the set ConcurrentSkipListSet<String> set = new ConcurrentSkipListSet<String>(); // Adding elements to this set set.add( "Gfg" ); set.add( "is" ); set.add( "fun" ); // Checks if Gfg is present in the set if (set.contains( "Gfg" )) System.out.println( "Gfg is present in the set." ); else System.out.println( "Gfg is not present in the set." ); } } |
输出:
Gfg is present in the set.
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END