【发布时间】:2014-03-29 04:30:16
【问题描述】:
大家好,我正在完成这个 java 项目的最后一步,我想我知道从哪里开始这个最后的部分,但我不知道该怎么做。
我应该:
修改一个类,使 toString 方法在遍历列表之前对牛列表和马列表进行排序。 (我应该做的一个例子)
我该如何开始?牛和马的列表是数组列表的一部分。
会涉及收藏吗?这是我的 toString 方法的代码。
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String output = "**************************************************\n"
+ "* List of Horses *\n"
+ "**************************************************\n";
for( Horse horse : listOfHorses )
{
output += horse + "\n"
+ "--------------------------------------------------\n";
}
output += "\n**************************************************\n"
+ "* List of Cows *\n"
+ "**************************************************\n";
for( Cow cow : listOfCows )
{
output += cow + "\nVisit Rate:\t\t\t"
+ fmt.format( cow.getBillAmount() ) + "\n"
+ "--------------------------------------------------\n";
}
return output;
【问题讨论】:
标签: java list sorting arraylist tostring