Wednesday, July 3, 2024
HomeLanguagesJavaConcurrentSkipListSet contains() method in Java

ConcurrentSkipListSet contains() method in Java

The contains() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns a true boolean value if the specified element is present in this set otherwise it returns false.

Syntax:

ConcurrentSkipListSet.contains(Object o)

Parameters: The function accepts a single parameter o i.e. to be checked for the presence in this set.

Return Value: The function returns a Boolean value. It returns True if the specified element is present in this set else it returns False.

Below programs illustrate the ConcurrentSkipListSet.contains() method:

Program 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.");
    }
}


Output:

9 is not present in the set.

Program 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.");
    }
}


Output:

Gfg is present in the set.

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#contains-java.lang.Object-

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments