所以我有一個叫Employee的類,我在其中創建了一個ArrayList
。我試圖打印列表的值,但他們打印每個元素的對象引用。我忘了如何做到這一點,我試圖在其他地方查找它,但似乎無法找到答案。如何在字符串中打印數組列表的值?
這裏是Employee類:
public class Employee {
int employeeID;
String employeeName;
public Employee(int employeeId, String employeeName){
this.employeeID = employeeId;
this.employeeName = employeeName;
}
...
這裏就是我打印我的價值觀:
public void printArrListValues() {
for(Employee x: employeeList){
System.out.println(x);
}
// Arrays.toString(employeeNameLst);
}
我曾嘗試在X上使用.toString()
,然而這並沒有解決問題。
打印到控制檯上這對我說:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
BUILD SUCCESSFUL (total time: 0 seconds)
添加'的toString()''到Employee'。 – markspace 2015-01-09 23:28:51
爲什麼不使用'Vector'或'HashMap'。它更容易檢索集合 – TheUknown 2015-01-09 23:38:14
中的隨機值'Vector'已被Java 1.2中的'ArrayList'取代。 – ajb 2015-01-10 00:02:27