The Artima Developer Community
Sponsored Link

Java Buzz Forum
Check if a particular value exists in Java TreeSet example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
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
Reply to this message Reply

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?

  1. package com.TreeSetExamplePrograms;

  2. public Class TreeSetDemo{ 
  3.  
  4. public static void main(String args[]) {
  5. //create TreeSet object
  6.  TreeSet<String> treeSet = new TreeSet<String>();
  7.        
  8.  //add elements to TreeSet
  9.   treeSet.add("1");
  10.   treeSet.add("3");
  11.   treeSet.add("2");
  12.   treeSet.add("5");
  13.   treeSet.add("6");
  14.   treeSet.add("7");
  15.   treeSet.add("8");
  16.   treeSet.add("9");
  17.   treeSet.add("10");
  18.         
  19.  boolean isExists = treeSet.contains("5");
  20.  System.out.println("5 exists in treeSet ?  " + isExists); 

  21. }
  22. }



Output:


  1. 5 exists in treeSet ? :true

1.Basic Java program to add elements ans display all elements



  1. package com.TreeSetExamplePrograms;
  2. import java.util.Scanner;
  3. public Class TreeSetDemo{ 
  4.  
  5. public static void main(String args[]) {
  6. //create TreeSet object
  7.  TreeSet<Integer> treeSet = new TreeSet<Integer>();
  8.        
  9.  //add elements to TreeSet
  10.   treeSet.add(1);
  11.   treeSet.add(3);
  12.   treeSet.add(2);
  13.   treeSet.add(5);
  14.   treeSet.add(6);
  15.   treeSet.add(7);
  16.   treeSet.add(8);
  17.   treeSet.add(9);
  18.   treeSet.add(10);
  19.         

  20.  System.out.println(treeset); 

  21. }
  22. }

Output:


  1. [1, 2, 3, 5, 6, 7, 8, 9, 10]

treeset add elements in java example program

Read: Check if a particular value exists in Java TreeSet example

Topic: SQL: Counting Groups of Rows Sharing Common Column Values Previous Topic   Next Topic Topic: GWT Sample Application Example

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use