
Hi
i have class A , i have added employee name and id in arraylist, then how can i find out all infomation of class A using emplyee id .
Thanks
kalins Naik

Here is an example that stores employee data into an arraylist and display the data of the particular employee according to the id entered by the user.
import java.util.*;
class EmployeeData
{
String name;
String address;
int id;
EmployeeData(String name,String address,int id){
this.name=name;
this.address=address;
this.id=id;
}
public String getName(){
return name;
}
public String getAddress(){
return address;
}
public int getId(){
return id;
}
public static void main(String []args){
ArrayList<EmployeeData> list=new ArrayList<EmployeeData>();
list.add(new EmployeeData("A","Delhi",2));
list.add(new EmployeeData("B","Mumbai",1));
list.add(new EmployeeData("C","Agra",4));
list.add(new EmployeeData("D","Kolkata",3));
list.add(new EmployeeData("E","Goa",5));
list.add(new EmployeeData("F","Chennai",8));
list.add(new EmployeeData("G","Lucknow",7));
list.add(new EmployeeData("H","Mathura",10));
list.add(new EmployeeData("I","Delhi",6));
list.add(new EmployeeData("J","Kanpur",9));
Scanner input=new Scanner(System.in);
System.out.print("Enter id: ");
int i=input.nextInt();
for(EmployeeData e : list){
if(i==e.getId()){
System.out.println(e.getName()+" \t "+e.getAddress()+" \t "+e.getId());
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.