我是 Java 新手,并试图使用Collections.shuffle()
来打乱我的 ArrayList 的元素。有人可以帮忙吗?
public class tracklist {
ArrayList<File> tracklist = new ArrayList<File>();
String trackListName;
public static void shuffle(List<?> tracklist, Random rnd) {
tracklist.shuffle();
}
}
public class TestDrive {
public void main(String[] args) {
//test basic MP3 player
Mp3Player mp = new Mp3Player();
File myMusicFile = new File("u:\\02.wav");
mp.play(myMusicFile);
//test advanced MP3 player
Mp3Advance adv = new Mp3Advance();
//Populate your favs play list or change its name
tracklist favs = new tracklist();
favs.addSong(new File("u:\\02.wav"));
favs.addSong(new File("u:\\03.wav"));
adv.playTracklist(favs);
System.out.println("Now Playing:" + favs + "playlist");
//shuffle play list
Collections.shuffle(favs);
System.out.println("Now playing" + favs + "playlist in shuffle");
}
}
我已经上传了我的试驾和曲目列表代码来提供帮助。我认为我只是试图洗牌错误的对象。
任何帮助将不胜感激。