This is a follow-up to my previous question (found here). My properties files so far consists of simple key-value pairs, like ints and Strings. I would now like to use it to place some more advanced structures in it, more specifically I need a Map<A, Integer> where A is a class i have defined, for example like so:
foo=bar,5;baz,10
Is this possible? If so, how should I format the file and parse the map, respectively?
Are there perhaps better ways to solve this?
Have you considered using a split() and trim().
Please see below:
ResourceBundle rb = ResourceBundle.getBundle(Prop.class.getName());
String fooValue = rb.getString("foo");
String[] firstSplit = fooValue.split(";");
for(String first : firstSplit){
String firstTrim = first.trim();
String[] intAndString = firstTrim.split(",");
if(intAndString.length == 2){
String intString = intAndString[0].trim();
String stringVal = intAndString[1].trim();
//TODO add entries here or return value.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With