HashMap<字符串 ,布尔值>将所有键复制到 HashMap并将值初始化为零 字符串>
最好的办法是什么?
只需循环并输入键和零,或者是否有另一种更优雅或现有的库方法。我也在使用 Google 的 guava java 库,它是否有任何有用的功能?
想检查是否有类似于列表复制方法或Map的putAll 方法,但仅用于键。
What is the best way ?
Just looping through and putting the key and zero, or is there another more elegant or existing library method. I am also using Google's guava java library if that has any useful functionality ?
Wanted to check if there was anything similar to the copy method for lists, or Map's putAll method, but just for keys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要认为这里有太多需要任何花哨的东西:
如果你确实想要 Guava 的一些花哨的东西,有这个选项:
Don't think there's much need for anything fancy here:
If you do want something fancy with Guava, there is this option:
循环非常简单(而且并不不优雅)。迭代原始
Map
的键,并将其放入新副本中,且值为零。希望有帮助。
Looping is pretty easy (and not inelegant). Iterate over the keys of the original
Map
and put it in them in the new copy with a value of zero.Hope that helps.