本文共 1751 字,大约阅读时间需要 5 分钟。
java treemap
keySet() method is available in java.util package.
keySet()方法在java.util包中可用。
keySet() method is used to return a set of keys that exists in this TreeMap to be viewed in a Set.
keySet()方法用于返回此TreeMap中存在的一组键,以便在Set中进行查看。
keySet() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
keySet()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。
keySet() method does not throw an exception at the time of returning the key set.
返回键集时, keySet()方法不会引发异常。
Syntax:
句法:
public Set keySet();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is Set, it returns contained set of keys in this TreeMap to be viewed in a Set.
方法的返回类型为Set ,它返回此TreeMap中包含的键集,以在Set中查看。
Example:
例:
// Java program to demonstrate the example // of Set keySet() method of TreeMap import java.util.*;public class KeySetOfTreeMap { public static void main(String[] args) { // Instantiates TreeMap TreeMap < Integer, String > tm = new TreeMap < Integer, String > (); // By using put() method is // to put the key-value pairs in // treemap tm tm.put(1, "C"); tm.put(4, "C++"); tm.put(3, "Java"); tm.put(2, "Php"); // Display TreeMap tm System.out.println("tm: " + tm); // By using keySet() method is to // return the set of keys to be // viewed in a Set Set s = tm.keySet(); // Display set view of TreeMap System.out.println("tm.keySet(): " + s); }}
Output
输出量
tm: {1=C, 2=Php, 3=Java, 4=C++}tm.keySet(): [1, 2, 3, 4]
翻译自:
java treemap
转载地址:http://lttzd.baihongyu.com/