如何经过构造初始化HashSet值? - How to initialize HashSet values by construction?

问题:

I need to create a Set with initial values. 我须要建立一个具备初始值的Set this

Set<String> h = new HashSet<String>();
h.add("a");
h.add("b");

Is there a way to do this in one line of code? 有没有办法在一行代码中作到这一点? For instance, it's useful for a final static field. 例如,它对于最终的静态字段颇有用。 spa


解决方案:

参考一: https://stackoom.com/question/8Z9u/如何经过构造初始化HashSet值
参考二: https://oldbug.net/q/8Z9u/How-to-initialize-HashSet-values-by-construction
相关文章
相关标签/搜索