in my code have
SearchBean sb=new SearchBean();
final static ArrayList<SearchBean> result=new ArrayList<SearchBean>();
public void addData()
{
.
. (Adding data from data base into SearchBean object
.
result.add(sb);
}
public ArrayList<SearchBean> sendResult()
{
return result;
}
Now i’m return result. first time it is giving correct but second time again that object also will be adding.
for example first time searching result syam(correct result)
in second time searching actually Ram is the coorrect result but syam,Ram also coming…
please help me …
how to remove old data into ArrayList?
Make it a local variable instead of a
staticfield.In general, using a local variable instead of a field is a good idea, but in your case it would fix a bug. 😉
I would have method like
or
or
in each case you can see