[英]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.