my first list1 , list show right values second list1 shows nothing:
public class icslist { arraylist<string> list1= new arraylist<string>(); public arraylist<string> list(arraylist list){ this.list1= list; log.i("list1", "" + list1); log.i("list", "" + list); setlist(); return list; } public arraylist setlist(){ log.i("list1", "" + list1); return list1; }
here logcat:
04-27 21:45:10.094 31548-31597/com.parse.starter i/list﹕ [b soccer @ liberty, apr 28 2015 5:30 pm, kghs athletics, g soccer v liberty (home), apr 28 2015 5:30 pm, kghs athletics 04-27 21:45:10.133 31548-31597/com.parse.starter i/list1﹕ [b soccer @ liberty, apr 28 2015 5:30 pm, kghs athletics, g soccer v liberty (home), apr 28 2015 5:30 pm, kghs athletics 04-27 21:45:10.133 31548-31548/com.parse.starter i/list1﹕ []
by way i'm trying use arraylist in class adding string values array list in class. setlist() making empty? , should instead "return this.list1". way there arraylist in class , calling list.(arraylist). getter going called in class retrieve arraylist. class relay between two.
in first class set arraylist in icslist:
arraylist<string> arraylist = new arraylist(); //add arraylist icslist list = new icslist(); list.list(arraylist);
class retrieved icslist:
arraylist<string> arraylist = new arraylist(); icslist list = new icslist(); arraylist= list.setlist();
taylor: based on last answer - have misunderstandings:
class icslist has static list1. means instances share same 1 list1 arraylist. so, whoever , whenever uses class - 1 same list1 object.
even more strange - initialize list1 in constructor of icslist. means list1 null until create @ least 1 instance of icslist. impractical , confusing. worse - every new icslist() update list1 new fresh , empty arraylist. weird too.
your last code shows create list2 , override list1 reference. has no sense either.
i assume want this:
public class icslist { private arraylist<string> list1; public icslist(){ list1 =new arraylist<string>(); } public static arraylist<string> getlist1(){ return list1; } }
then second 1 right (assuming honey "honey") , third 1 be
arraylist<string> list2= = icslist.getlist1(); // list1 existing object icslist if (list2.contains(honey)) system.out.println("honey here"); if (icslist.getlist1().contains(honey)) system.out.println("honey still here");