The following example code demonstrates How to Create a Vector of Objects in Java.

Define a class Emp with the following fields – emp_id, name, salary, gender, department, and email_id. Also, define the corresponding constructors, and getter and setter methods. Further, override the toString() method to display the details of the employee. Now create another class EmpList, that has an LinkedList as its data member. In this class, define two methods – addEmp(Emp ob), and deleteEmp(int eid) that adds and removes an Emp object in the list. Also, create methods to display minimum salary, maximum salary, average salary, and search an employee using the given emp_id. Finally, test the program using the main() method.

Here is an example implementation of the classes in Java. The following code shows the implementation for the Emp class.

public class Emp {
  private int emp_id;
  private String name;
  private double salary;
  private char gender;
  private String department;
  private String email_id;
  
  public Emp(int emp_id, String name, double salary, char gender, String department, String email_id) {
    this.emp_id = emp_id;
    this.name = name;
    this.salary = salary;
    this.gender = gender;
    this.department = department;
    this.email_id = email_id;
  }
  
  public int getEmp_id() {
    return emp_id;
  }
  
  public void setEmp_id(int emp_id) {
    this.emp_id = emp_id;
  }
  
  public String getName() {
    return name;
  }
  
  public void setName(String name) {
    this.name = name;
  }
  
  public double getSalary() {
    return salary;
  }
  
  public void setSalary(double salary) {
    this.salary = salary;
  }
  
  public char getGender() {
    return gender;
  }
  
  public void setGender(char gender) {
    this.gender = gender;
  }
  
  public String getDepartment() {
    return department;
  }
  
  public void setDepartment(String department) {
    this.department = department;
  }
  
  public String getEmail_id() {
    return email_id;
  }
  
  public void setEmail_id(String email_id) {
    this.email_id = email_id;
  }
  
  @Override
  public String toString() {
    return "Emp_id: " + emp_id + ", Name: " + name + ", Salary: " + salary + ", Gender: " + gender + ", Department: " + department + ", Email_id: " + email_id;
  }
}

Similarly, here is the code for the EmpList class.

import java.util.Vector;

public class EmpList {
  private Vector<Emp> empList;
  
  public EmpList() {
    empList = new Vector<>();
  }
  
  public void addEmp(Emp ob) {
    empList.add(ob);
  }
  
  public void deleteEmp(int eid) {
    for (Emp emp : empList) {
      if (emp.getEmp_id() == eid) {
        empList.remove(emp);
        break;
      }
    }
  }
  
  public double getMinSalary() {
    double minSalary = empList.get(0).getSalary();
    for (Emp emp : empList) {
      if (emp.getSalary() < minSalary) {
        minSalary = emp.getSalary();
      }
    }
    return min
}


Further Reading

Understanding Enterprise Java Beans

Java Practice Exercise

programmingempire

Princites