目录

Collection<V> values()

描述 (Description)

values()方法用于返回此映射中包含的值的Collection视图。 集合的迭代器以相应键的升序返回值。

声明 (Declaration)

以下是java.util.TreeMap.values()方法的声明。

public Collection<V> values()

参数 (Parameters)

NA

返回值 (Return Value)

方法调用返回此映射中包含的值的集合视图。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.TreeMap.values()的用法

package com.iowiki;
import java.util.*;
public class TreeMapDemo {
   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]
↑回到顶部↑
WIKI教程 @2018