Shortest way to reverse Properties

后端 未结 3 1483
一生所求
一生所求 2021-01-22 09:05

In Java I have a java.util.Properties object and I want to obtain another one with the same pairs but keys converted to values and viceversa.

If there are c

3条回答
  •  [愿得一人]
    2021-01-22 10:05

    Something like:

    Properties fowards = new Properties();
    fowards.load(new FileInputStream("local.properties"));
    
    Properties backwards = new Properties();
    
    for (String propertyName : fowards.stringPropertyNames())
    {
      backwards.setProperty(forwards.get(propertyName), propertyName);
    }
    

提交回复
热议问题