// Check this example
public class Test {
public static void main(String[] args){
List<Student> al = new ArrayList<Student>();
Student s1 = new Student(1, "John", "Nash", "N");
Student s2 = new Student(2, "John", "Slash", "s");
al.add(s1);
al.add(s2);
for(Student s:al){
if(s.getId() == 2){
s.setfNmae("Nks");
al.add(al.indexOf(s), s);
}
s.display();
}
}
}
class Student{
private int id;
private String fName;
private String lName;
private String initial;
Student(int id, String fName, String lName, String initial){
this.id = id;
this.fName = fName;
this.lName = lName;
this.initial = initial;
}
void display(){
System.out.println(id);
System.out.println(fName);
System.out.println(lName);
System.out.println(initial);
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the fNmae
*/
public String getfNmae() {
return fName;
}
/**
* @param fNmae the fNmae to set
*/
public void setfNmae(String fNmae) {
this.fName = fNmae;
}
/**
* @return the lName
*/
public String getlName() {
return lName;
}
/**
* @param lName the lName to set
*/
public void setlName(String lName) {
this.lName = lName;
}
/**
* @return the initial
*/
public String getInitial() {
return initial;
}
/**
* @param initial the initial to set
*/
public void setInitial(String initial) {
this.initial = initial;
}
}