I have a string in the form "1=xyz,2=zyx,3=blah", and an object
public class Foo{
String a,b,c
/*gets and sets*/
}
I'd like to instantiate this object so that a = xyz, b = zyx, and c = blah. What I have so far is,
for(String[] split1 : originalString.split(","){
for(String[] split2 : split1.split("="){
if(split2[0] == 1){foo.setA(split2[1])}
if(split2[0] == 2 {...}
}
}
And what I want to know is, is there a cleaner way to do this than with a bajillion if statements? Is there a way to create a Map between the keys in the original list with setters in my pojo?
I found some older questions on this, but I was wondering if java 8 might have added something for this. I don't want to use Reflection (nor should I)