0

I'm working on a spring application where I need to get a Map from the property file. The sample Java code is

public static final Map<String, List<String>> txn = Collections.unmodifiableMap(new HashMap<String, List<String>>(){{
    put("DIV",Arrays.asList("AA","CD","DD","EF"));
    put("TFER", Arrays.asList("J","TE","EF","RE"));
    put("PPO", Arrays.asList("PPIN","PPOUT"));
}});

Instead, the map txn needs to be mapped with values from the properties file. The property file looks like this

txn.type=DIV,TFER,PPO
DIV.values=AA,CD,DD,EF
TFER.values=J,TE,EF,RE
PPO.values=PPIN,PPOUT

I need the java program to get the values into the Map declaration from the properties file.

chaitunakka
  • 11
  • 1
  • 6
  • 2
    Have you tried anything yet? – Mureinik Jun 15 '17 at 17:32
  • 2
    Check this answer: [https://stackoverflow.com/questions/28369458/how-to-fill-hashmap-from-java-property-file-with-spring-value/28370899#28370899](https://stackoverflow.com/questions/28369458/how-to-fill-hashmap-from-java-property-file-with-spring-value/28370899#28370899). It's very close (if not the same) to what you need. – fps Jun 15 '17 at 17:48
  • “Double brace” initialization of Maps or Collections is not advisable. See https://stackoverflow.com/questions/924285/efficiency-of-java-double-brace-initialization. – VGR Jun 15 '17 at 21:43

0 Answers0