7:56 am - Friday March 24, 2017

Retrieve all values in a Treemap Collection values()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK 

                           This tutorial explains how  to Retrieve all values in a Treemap  Collection<V> values().

 The sorting may be happen based on the values and also key too.

Example

import java.util.TreeMap;
public class TreeMapValues

{

public static void main(String[] args)

{

   TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();

   treemap.put(2, "two");

   treemap.put(1, "one");

   treemap.put(3, "three");

   treemap.put(6, "six");

   treemap.put(5, "five");

   System.out.println("Getting collection from the map");

   Collection<String> coll=treemap.values();

   System.out.println("Value of the collection: "+coll);

 }

}

Output 

           Getting collection from the map

          Value of the collection: [one, two, three, five, six]

BACK

Filed in: Java Examples

Comments are closed.