class Main
{
public static void main()
{
Student one=new Student();
one.setName("firstname");
AllStudent all=new AllStudent();
all.add(one);
// Now changing name of student
one.setName("secondname");
// Here I getAll Students
Collection<Student> cs=all.getAll();
java.util.Iterator<Student> itr=cs.iterator();
while(itr.hasNext()){
Student rgc=itr.next();
System.out.println(rgc.getName());
}
}
clas public Student
{
String name;
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
}
clas public AllStudent
{
Collection<Student> stds;
public void addAll(Collection<Student> stds)
{
this.stds=stds;
}
public void add(Student std)
{
stds.add(std);
}
public Collection<Student> getAll()
{
return stds;
}
}
}
Now this will give me “firstname”.
But I want to get “secondname”. So what I have to do? If any change in API or to create new class?
try this it’s your code i just implement something in that
I have run and got the secondname