unable to retrieve value of list from one method to another
I have ids in a list inside a method called displayid(). I use getters and setters. When try to retrieve the ids from another method Mid(), i am unable to retrieve all values. Only last value is printed. Here is my code
void displayId(PrintWriter stdOut, StringResources resources, IPatchBundle group){
List ids = new ArrayList();
String MIds=spec.getId();
ids.add(MIds);
ar.setMid(ids);
System.out.println("M Ids of specific group "+MIds);
}
Outp开发者_如何学运维ut:
M Ids of specific group M05632s
M Ids of specific group M05633s
M Ids of specific group M05634s
Code:
public boolean cmdMId(InputStream stdIn, PrintWriter stdOut, StringResources resources, Arguments args, Object data){
List ids=new ArrayList();
ids.add(ar.getMid());
System.out.println("ar.getMid()=======>"+ar.getM());
return true;
}
Output: //Here i need all the three values but i get only the last value ar.getMid()=======>M05634s
Getter setter
public List getMid(){
return mid;
}
public void setMid(List mid){
this.mid=mid;
}
Please help me to solve this
What is spec.getId();
how many Ids does it give?
You have to run the part:
String MIds=spec.getId();
ids.add(MIds);
for all three Ids, i guess you add only the last one, you can check this buy setting a breakpoint and look how many times do you access the ids.add() methode.
精彩评论