The Artima Developer Community
Sponsored Link

Java Buzz Forum
Get lowest and highest value stored 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.
Get lowest and highest value stored in Java TreeSet example Posted: Mar 8, 2016 12:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Get lowest and highest value stored 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 example program get lowest and highest values from treeset

  1. package com.TreeSetExamplePrograms;

  2. public Class TreeSetGetLowestAndHighestDemo{ 
  3.  
  4. public static void main(String args[]) {
  5. //create TreeSet object
  6.  
  7.  
  8.  TreeSet<Integer> treeSet = new TreeSet<Integer>();
  9.        
  10.  //add elements to TreeSet
  11.   treeSet.add(1);
  12.   treeSet.add(3);
  13.   treeSet.add(2);
  14.   treeSet.add(5);
  15.   treeSet.add(6);
  16.   treeSet.add(7);
  17.   treeSet.add(8);
  18.   treeSet.add(9);
  19.   treeSet.add(10);
  20.           
  21.  System.out.println(treeSet);
  22.           
  23.  System.out.println("First element in treeset : " + treeSet.first());           
  24.    
  25.  System.out.println("Last element in treeste" + treeSet.last()); 


  26. }
  27. }


Output:


  1. [1, 2, 3, 4, 5, 6, 7, 8, 9,10]
  2. First element in treeset :1
  3. Last element in treeset :10


2.Basic Java example program print elements of treeset using iterator


  1. package com.TreeSetExamplePrograms;

  2. public Class TreeSetDemo{ 
  3.  
  4. public static void main(String args[]) {
  5. //create TreeSet object
  6.  
  7.  TreeSet<String> treeSet = new TreeSet<String>();
  8.  
  9.    //add elements to TreeSet
  10.     treeSet.add("I");
  11.     treeSet.add("N");
  12.     treeSet.add("S");
  13.     treeSet.add("T");
  14.     treeSet.add("A");
  15.     treeSet.add("N");
  16.     treeSet.add("C");
  17.     treeSet.add("E");
  18.           
  19.     treeSet.add("O");
  20.     treeSet.add("F");
  21.   
  22. Iterator itr = treeSet.iterator();
  23. while(itr.hasNext()){
  24.              System.out.println(itr.next());
  25. }

  26. }
  27. }


Output:

  1. A
  2. C
  3. E
  4. F
  5. I
  6. N
  7. O
  8. S
  9. T

Read: Get lowest and highest value stored in Java TreeSet example

Topic: DBCP Connection Pooling Example Previous Topic   Next Topic Topic: Kubernetes Namespaces, Resource Quota, and Limits for QoS in Cluster

Sponsored Links



Google
  Web Artima.com   

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