• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList of Methods of pojo like scenario.  RSS feed

 
Patel Brijesh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have class with name Person consisting three class instance variable name,state and age and its setter getter methods.
and I have ArrayList of size three in which values are data[0]="jag", data[1]="Maharashtra" and data[2]="35";
Is there any way that I can set these values( using setter method) while iterating through list,without using method setAll(String,String,String) like setAll(data[0],data[1],data[2]).
I dont want hardcode like

for (int i=0;i<Data.size();i++){
if(i==0) p.setName(Data[0];
if(i==1) p.setName(Data[1];
if(i==2) p.setName(Data[2];
}


}
(consider an array size of 100 practicaly.)


If Any can Answer please.
Thanks,
Brijesh.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

the only thing that i would think is possible and save you code lines is create a mehtod on your bean that takes the list like

setData(List<Object> l)

and use reflections to parse the content of the list into your bean ,...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets. For more information, please read this.

This post has been moved to a more appropriate forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!