This discussion is archived
9 Replies Latest reply: Oct 16, 2009 8:19 AM by 807580 RSS

return string

807580 Newbie
Currently Being Moderated
Hi Guys,

I think simple things to me aint getting simple nemore.

Ok, all i want to do is to loop through an array, and then selects its value.


for example:
class class1{

private String name;

public class1(){
 ArrayList<String> a = new ArrayList<String>();
   a.add("name1");
   a.add("name2");
   a.add("name3")

   for(int x=0; x < a.size(); x++){
      setName(a.get(x));
   }
}


public String setName(String name){
 this.name = name;
}

public String getName(){
    return name;
  }
}
and then in class two..
  public class2{

  public class2(){
     System.out.println(new class1().getName());
 } 
}
Above results in printing only name3. Do anyone knows what i am doing wrong?

mm