我創建了一個類employee.it,它有四個變量name,id,salary,city.i創建了一個僱員類對象的數組列表。當我運行該文件時,它只顯示defaullt values.But我想在我的數組list.what應該怎麼做添加一個以上的價值嗎?請幫我解決這個這裏是我的代碼在數組列表中添加多個值
import java.util.*;
public class arraylist {
public static void main(String[] args) {
new arraylist();
}
public arraylist() {
List<Employee > listOfEmp = new ArrayList<Employee >();
Employee bk1 = new Employee();
listOfEmp .add(bk1);
System.out.println(" emp = " + bk1);
System.out.println("listOfEmployee(0) = " + listOfEmp.get(0));
}
public class Employee {
String name="sarah";
int id =102;
String city="orny";
int salary=13000;
// @Override
public String toString() {
return "Employee: name = " + name + "; Id = " + id + "; City = " + city + "; Salary = " + salary + "; hashCode = " + hashCode();
}
}
}
那麼你想從哪裏得到變量的值? –
使用getters&setters – Madhan