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)).
import java.util.Set;
import java.util.TreeSet;
public class ContailsElement {
public static void main(String[] args) {
Set<String> ts = new TreeSet<String>();
ts.add("mumbai");
ts.add("delhi");
ts.add("kolkata");
ts.add("chandigarh");
ts.add("dehradun");
// print treeset
System.out.println(" ts ="+ts);
System.out.println(ts.contains("java"));
System.out.println(ts.contains("delhi"));
System.out.println(ts.contains("php"));
}
}
Output:
ts =[chandigarh, dehradun, delhi, kolkata, mumbai]
false
true
false
o.equals(e)).
import java.util.Set;
import java.util.TreeSet;
public class ContailsElement {
public static void main(String[] args) {
Set<String> ts = new TreeSet<String>();
ts.add("mumbai");
ts.add("delhi");
ts.add("kolkata");
ts.add("chandigarh");
ts.add("dehradun");
// print treeset
System.out.println(" ts ="+ts);
System.out.println(ts.contains("java"));
System.out.println(ts.contains("delhi"));
System.out.println(ts.contains("php"));
}
}
Output:
ts =[chandigarh, dehradun, delhi, kolkata, mumbai]
false
true
false
No comments:
Post a Comment