我有哪些存储标题,艺术家和时间 我有我所有的代码写出来的歌一个ArrayList和一切。我只想更多地了解Collection.sort和Collection.reverse和Collection.reverseOrder。我有一个包含所有歌曲和所有内容的文件。 我想按照时间降序排列歌曲。
当我尝试这个时,我要么得到一个错误,要么它没有正确排序。任何人都可以建议如何我 不能使用Collection.sort和使用比较
Comparator<Song> comparator = Collections.reverseOrder();
Collections.reverse(listOfSongs);
我的比较方法如下:
public int compare(Song mySong1,Song mySong2){
if (mySong1.getLength() > mySong2.getLength()){
return -1;
}
if(mySong1.getLength() < mySong2.getLength()){
return 1;
}
if(mySong1.getLength() == mySong2.getLength())
{
if(mySong1.getTitle().compareTo(mySong2.getTitle()) > 0){
return -1;
}
if(mySong1.getTitle().compareTo(mySong2.getTitle()) < 0){
return 1;
}
else {
if(mySong1.getComposer().compareTo(mySong2.getComposer()) >0){
return -1;
}
if(mySong1.getComposer().compareTo(mySong2.getComposer()) <0) {
return 1;
}
}
}
return 0;
}
什么类型的对象存储在ArrayList中? – adarshr
男人,你有没有做另一个帐户?这个问题在过去的24小时里出现了5次。 –
它们是ArrayList中的歌曲对象 – Pachun