将 javafx.util.Properties 转换为 HashMap
我想知道是否有一种简单的方法将 javafx.util.Properties 对象转换为 java.util.HashMap。
有一种显而易见的方法可以从 Properties 对象中获取每个值并将其放入 Map 中。但对于大量属性,似乎应该有一种方法来获取支持 javafx.util.Properties 的 Map(如果它是 Map)。
预先感谢您的任何建议。
I was wondering if there is an easy way to convert the javafx.util.Properties object to a java.util.HashMap.
There is the obvious way of getting each value from the Properties object and putting it in a Map. But with a large number of properties it seems like there should be a way of just getting the Map that backs javafx.util.Properties (if it is a Map).
Thanks in advance for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的不知道
javafx.util.Properties
是否由 JavaMap
支持,但由于公共 API 没有提及任何获取此地图的方法,因此您可能不应该这样做尝试这样做 - 即使它是可能的(例如通过扩展Properties
类),它也可能在未来的版本中发生变化。我会继续复制每个元素。
I don't really know if
javafx.util.Properties
are backed by JavaMap
, but since public API does not mention any way to get this map you probably shouldn't try to do it - even if it was possible (e.g. by extendingProperties
class) it might change in future versions.I would stay with copying every element.
pazabos 的回答+1。但我会采取相反的方式:扩展 HashMap 或 java.util.Properties,然后可以导出 javafx.util.Properties (或保存一个实例)。喜欢:
+1 for pazabos answer. But I would go the other way around: extend HashMap or java.util.Properties which then could export javafx.util.Properties (or hold an instance) sth. like: