[英]Java Properties.load() - how to switch key value pairs?
I need to read in a Properties object from a file, however I need to switch the key and value pairs around, ie I need the keys to become the property values and vice-versa. 我需要从文件中读取一个Properties对象,但是我需要切换键和值对,即我需要键成为属性值,反之亦然。 I also cannot just change this on the file I am reading in. Any ideas how I could do this?
我也不能只在我正在阅读的文件中更改此内容。有任何想法我怎么能这样做?
Thanks 谢谢
您可以创建第二个Properties
对象,遍历刚刚读过的entires,调用put(entry.getValue(), entry.getKey())
然后就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.