
An arraylist object stores an Emp Object, where there is name,age,address of the employee is stored,
And i want to access the data in the basis of age based?
Provide answer to the question with an example..

import java.util.*;
class EmployeeData
{
String name;
String address;
int age;
EmployeeData(String name,String address,int age){
this.name=name;
this.address=address;
this.age=age;
}
public String getName(){
return name;
}
public String getAddress(){
return address;
}
public int getAge(){
return age;
}
public static void main(String []args){
ArrayList<EmployeeData> list=new ArrayList<EmployeeData>();
list.add(new EmployeeData("A","Delhi",22));
list.add(new EmployeeData("B","Mumbai",23));
list.add(new EmployeeData("C","Agra",24));
list.add(new EmployeeData("D","Kolkata",25));
list.add(new EmployeeData("E","Goa",22));
list.add(new EmployeeData("F","Chennai",23));
list.add(new EmployeeData("G","Lucknow",22));
list.add(new EmployeeData("H","Mathura",25));
list.add(new EmployeeData("I","Delhi",23));
list.add(new EmployeeData("J","Kanpur",24));
Scanner input=new Scanner(System.in);
System.out.print("Enter age: ");
int a=input.nextInt();
for(EmployeeData e : list){
if(a==e.getAge()){
System.out.println(e.getName()+" \t "+e.getAddress()+" \t "+e.getAge());
}
}
}
}
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.