我需要修改我的toString方法。這些指令是「修改toString方法,因此首先對薪水清單進行排序,然後遍歷它們一次打印出一個。我們不想將[]包含在元素中輸出「。我已經有了一個我可以通過PayrollUtility.sortArray(array)調用的排序方法;我目前的toString()方法是:Java - 修改我的字符串方法
public String toString() {
return String.format("\n%-27s%s\n", "Employee ID:", employeeID) +
String.format("%-27s%s\n", "First Name:", firstName) +
String.format("%-27s%s\n", "Last Name:", lastName) +
String.format("%-27s%s\n", "Date of Birth:", dateOfBirth) +
String.format("%-27s%s\n", "Date Hired:", dateHired) +
String.format("%-27s%s\n", "Accrued Vacation Hours:", accruedVacationHours) +
String.format("%-27s%s\n", "Amount Paid Year to Date:", PayrollUtility.convertToCurrencyStringLeftAligned(yearToDate)) +
String.format("%-27s%s\n", "Paychecks Received:", listOfPaychecks);
}
我的問題是如何從顯示中刪除[]?我應該使用for循環遍歷薪水清單嗎?
編輯:我發現後立即發佈。謝謝你們的迅速反應。
「我應該使用for循環遍歷薪水列表嗎?」試試看看。 – 2014-11-24 03:56:05