instanceof java
Posts: 576
Nickname: instanceof
Registered: Jan, 2015
instanceof java is a java related one.
Check if a particular value exists in Java TreeSet example
Posted: Mar 8, 2016 6:11 AM
This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Check if a particular value exists in Java TreeSet example
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java
Advertisement
1.Basic Java program to check particular value present in TreeSet or not? package com.TreeSetExamplePrograms; public Class TreeSetDemo{ public static void main(String args[]) { //create TreeSet object TreeSet<String> treeSet = new TreeSet<String>(); //add elements to TreeSet treeSet.add("1"); treeSet.add("3"); treeSet.add("2"); treeSet.add("5"); treeSet.add("6"); treeSet.add("7"); treeSet.add("8"); treeSet.add("9"); treeSet.add("10"); boolean isExists = treeSet.contains("5"); System.out.println("5 exists in treeSet ? " + isExists); } }
Output:5 exists in treeSet ? :true 1.Basic Java program to add elements ans display all elements package com.TreeSetExamplePrograms; import java.util.Scanner; public Class TreeSetDemo{ public static void main(String args[]) { //create TreeSet object TreeSet<Integer> treeSet = new TreeSet<Integer>(); //add elements to TreeSet treeSet.add(1); treeSet.add(3); treeSet.add(2); treeSet.add(5); treeSet.add(6); treeSet.add(7); treeSet.add(8); treeSet.add(9); treeSet.add(10); System.out.println(treeset); } } Output:[1, 2, 3, 5, 6, 7, 8, 9, 10]
Read: Check if a particular value exists in Java TreeSet example