I’m getting an array with fixed size of let’s say 20.
I have to set each array element in a bean property, so my bean has 20 properties.
Here’s my current approach:
Object[] record = { "0", "1", "2", ...."19" };
for (int j = 0; j < record.length; j++) {
if (j == 0) {
bean.setNo((String) record[j]);
}
if (j == 1) {
bean.setName((String) record[j]);
}
if (j == 2) {
bean.setPhone((String) record[j]);
}
// so on and so forth...
}
This is how i’m setting every property of bean from array.
Here i have 20 elements in array.
So to set 20th element it is checking 20 conditions.. Performance issue..
Any optimized technique is appreciated…
Thanks in advance…
One way of doing this is :
Try this::
…………..
…………….
………….