我将对象添加到列表中,但是当我对列表进行排序时,所有内容都很好地排序了;最后仅添加新对象。有什么想法吗?
这是代码:
// creating object
ScheduleDay sDay = new ScheduleDay();
// all attributes are optional; but even if I add them all, it still isn't sorted
sDay.setDate(dt1.format(cal.getTime()));
// adding to the list
standardShiftItemsPerEmployee.add(sDay);
// sorting
Arrays.sort(standardShiftItemsPerEmployee.toArray());
for (ScheduleDay s : standardShiftItemsPerEmployee)
System.out.println(s.getDate());
结果:
2014年8月9日
2014年9月9日
2014年10月9日
2014年11月9日
2014年12月9日
2014年6月9日
最佳答案
将Arrays.sort(standardShiftItemsPerEmployee.toArray());
替换为Collections.sort(standardShiftItemsPerEmployee)
关于java - 对象被添加到列表中,但不与其他对象一起排序,而是添加到最后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25607888/