Java TreeMap values()方法

java.util.TreeMap.values() 返回TreeMap中包含value的集合。

1 语法

public Collection<V> values()

2 参数

3 返回值

返回TreeMap中包含value的集合。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.TreeMap.values()方法的例子
 */
import java.util.*;

public class Demo {
    public static void main(String[] args) {

        // creating maps
        TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();
        SortedMap<Integer, String> treemapincl = new TreeMap<Integer, String>();

        // populating tree map
        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 coll = treemap.values();
        System.out.println("Value of the collection: "+coll);
    }
}

输出结果为:

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

热门文章

优秀文章