【发布时间】:2018-06-15 13:16:30
【问题描述】:
我正在关注链接:How to initialize HashSet values by construction?,这可能是一个非常愚蠢的问题,但我没有成功,请指导。
public class Demo {
public static void main(String[] args) {
Set<Double> tempSet = new HashSet<Double>();
tempSet.add(11.0);
tempSet.add(22.0);
// Below both lines not working
Set<Double> tempSet1 = new HashSet<Double>({11.0, 22.0});
Set<Double> tempSet1 = new HashSet<Double>(){11.0, 22.0};
}
}
【问题讨论】:
-
Set<Double> tempSet1 = new HashSet<Double>({11.0, 22.0});无法编译。你想实现什么样的初始化? -
有没有办法在一行代码中做到这一点?
标签: java