TreeSet contains Example

TreeSet class contains example. This example shows you how to use contains method.


TreeSet class contains example.public 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)).

Here is the code

/**
 * @ # Contains.java
 * A class repersenting use to contains method 
 * of TreeSet class in java.util package
 * version 23 May 2008
 * author Rose India 
 */
import java.util.*;

public class Contains {

    public static void main(String args[]) {
        // Create a new TreeSet object:
        TreeSet ts = new TreeSet();

        // Create new element object and Add the elements to the set:
        ts.add(new Integer(2));
        ts.add(new Integer(5));
        ts.add(new Integer(7));

        // Check if the set contains "x":
        System.out.println("Check if the set contains 2: " + ts.contains(2));
    }
}

Output
Check if the set contains 2: true

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US