博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java treemap_Java TreeMap keySet()方法与示例
阅读量:2531 次
发布时间:2019-05-11

本文共 1751 字,大约阅读时间需要 5 分钟。

java treemap

TreeMap类的keySet()方法 (TreeMap Class keySet() method)

  • 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/

你可能感兴趣的文章
request.getContextPath() 路径正确但是资源加载不出来的解决方案
查看>>
SSM 实战项目①丨图书管理系统 丨技术储备丨(1)项目环境配置
查看>>
SSM 实战项目①丨图书管理系统 丨(0) 项目概要及本系列介绍
查看>>
JavaWeb项目的相对路径问题
查看>>
SSM 实战项目①丨图书管理系统 丨技术储备丨(2)RESTful API 接口设计总结
查看>>
SSM 实战项目①丨图书管理系统 丨(3) MyBatis Generator 拓展:支持多表联合操作
查看>>
SSM 实战项目①丨图书管理系统 丨(2) Mybatis Generator 的基本使用
查看>>
SSM 实战项目①丨图书管理系统 丨(1) SSM 整合
查看>>
SSM 实战项目①丨图书管理系统 丨(4) 登录操作的实现
查看>>
数据库系统丨关系代数运算总结
查看>>
数据库系统丨数据库完整性及其 SQL 实现
查看>>
数据库系统丨触发器小结
查看>>
数据库系统丨数据库常用恢复技术
查看>>
浅谈 J2EE Spring 框架中涉及到的设计原则和设计模式
查看>>
[已解决] SqlServer 2019 管道的另一端无任何进程错误233
查看>>
超详细 Swagger 使用指南(附带注解总结和源码)
查看>>
MybatisPlus|整合SpringBoot
查看>>
SpringBoot 整合模板引擎 Thymeleaf 页面跳转失败的解决方案
查看>>
SpringBoot 拓展 SpringMVC 的 2 步基本思路
查看>>
Mac 上安装 Redis 和配置密码详细过程
查看>>