[英]What is the best way to convert a TreeSet to populate a HashMap?
使用Java將TreeSet轉換為填充HashMap的最佳方法是什么? 例如:
SortedSet<Map.Entry<String, Double>> sortedset =
new TreeSet<Map.Entry<String, Double>();
至
Map<String, Double> map = new HashMap<String, Double>();
我可能是錯的,但我認為Java沒有內置任何功能來做到這一點。 最好的選擇是手動進行(這非常簡單):
for (Map.Entry<String, Double> entry : sortedSet)
map.put(entry.getKey(), entry.getValue());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.