Click here to Skip to main content
15,887,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
public class App {
                public static void main(String[] args) throws CloneNotSupportedException {
     ArrayList<employee> al1 = new ArrayList<employee>();

                              Employee e1 = new Employee(1, "rak", "gwda", "1011996", "2111996");
                              Employee e2 = new Employee(2, "sher", "gowda", "", "");
                              Employee e3 = new Employee(3, "raksher", "homles", "", "");
                              Employee e4 = new Employee(4, "sherrak", "hgowda", "10111996", "21111996");
                              Employee e5 = new Employee(5, "raksh", "hgowda", "", "");
                              al1.add(e1);
                              al1.add(e2);
                              al1.add(e3);
                              al1.add(e4);
                              al1.add(e5);
                              System.out.println(al1);


What I have tried:

Java
public class Employee {
	 private int id;
	    private String fname;
	    private String lname;
	    String doj;
	    String doe;
	    
	    
	    public Employee() {
	          super();
	          // TODO Auto-generated constructor stub
	    }


	    public Employee(int id, String fname, String lname, String doj, String doe) {
	          super();
	          this.id = id;
	          this.fname = fname;
	          this.lname = lname;
	          this.doj = doj;
	          this.doe = doe;
	    }


	    public int getId() {
	          return id;
	    }


	    public void setId(int id) {
	          this.id = id;
	    }


	    public String getFname() {
	          return fname;
	    }


	    public void setFname(String fname) {
	          this.fname = fname;
	    }


	    public String getLname() {
	          return lname;
	    }


	    public void setLname(String lname) {
	          this.lname = lname;
	    }


	    public String getDoj() {
	          return doj;
	    }


	    public void setDoj(String doj) {
	          this.doj = doj;
	    }


	    public String getDoe() {
	          return doe;
	    }


	    public void setDoe(String doe) {
	          this.doe = doe;
	    }


	    @Override
	    public String toString() {
	          return "Employee [id=" + id + ", fname=" + fname + ", lname=" + lname + ", doj=" + doj + ", doe=" + doe + "]";
	    }


}
Posted
Updated 20-Mar-20 4:18am
v3
Comments
ZurdoDev 20-Mar-20 8:20am    
Where are you stuck?

1 solution

Java
ArrayList<Employee> al2 = new ArrayList<Employee>();
al2.add(al1[0]); // Inserts the first element of al1 into al2
al2.add(al1[1]); // Inserts the second element of al1 into al2
                 // etc.
 
Share this answer
 
Comments
CPallini 20-Mar-20 10:30am    
5.
Maciej Los 20-Mar-20 13:06pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900