TreeMap.keySet Method

来源:互联网 发布:淘宝退款介入在哪里 编辑:程序博客网 时间:2024/05/16 01:53
Retrieves the set of keys in a TreeMap object.

Package:
java.util
Assembly: vjslib (in vjslib.dll)

Java代码 复制代码 收藏代码
  1. public java.util.Set keySet();  


Return Value:
The set of keys contained in the TreeMap object.

Example:

In this example, you create and initialize a TreeMap object, and then you display the keySet contained in the object.
Java代码 复制代码 收藏代码
  1. // TreeMap-keyset1.jsl   
  2. // TreeMap.keySet example   
  3.   
  4. import java.util.*;   
  5.   
  6. public class MyClass   
  7. {   
  8.     public static void main(String[] args)   
  9.     {   
  10.         // Create a TreeMap object:   
  11.         TreeMap tm = new TreeMap();   
  12.   
  13.         // Add some elements:   
  14.         tm.put("3","Sally Abolrous");   
  15.         tm.put("2","Craig Combel");   
  16.         tm.put("5","Pille Mandla");   
  17.   
  18.         // Remove the key set:   
  19.         System.out.println("The key set is: " + tm.keySet());   
  20.     }   
  21. }   
  22.   
  23. /*  
  24. Output:  
  25. The key set is: [2, 3, 5]  
  26. */