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]