如何經過構造初始化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
相關文章
相關標籤/搜索