keySet().toArray(new Double [0])有什么作用? [英] What does keySet().toArray(new Double[0]) do?

查看:656
本文介绍了keySet().toArray(new Double [0])有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下返回内容有什么作用?以及如何使用该值:

What does the following return do? And how can I use that value:

private Map<Double, String> theLabels = new HashMap<Double, String>();

public Double[] getTheLabels() {
  return theLabels.keySet().toArray(new Double[0]);
  }

这正确吗?

Double[] aD = theClassInQuestion.getTheLabels();

谢谢.

HJW

推荐答案

它将键集转换为Double s的数组.编译器/JVM需要参数new Double[0]来推断要返回的数组的正确类型. (如果array参数足够长以容纳所有键值,则将使用它,否则将创建具有所需长度的相同运行时类型的新数组.)

It converts the set of keys into an array of Doubles. The parameter new Double[0] is needed for the compiler/JVM to infer the correct type for the array to be returned. (If the array parameter is long enough to hold all key values, it will be used, otherwise a new array of the same runtime type will be created with the required length.)

这是您对返回值的分配是正确的.

Your assignment of the return value is correct.

这篇关于keySet().toArray(new Double [0])有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆