public void playSpecificSong(String specificSong) {
String nextSong = songQueue.remove();
while (!nextSong.equals(specificSong) && !songQueue.isEmpty()) {
nextSong = songQueue.remove();
}
if (nextSong.equals(specificSong)) {
// specific song was found in the queue and is held within the nextSong variable
// songQueue now contains all songs AFTER specificSong and nothing before
} else {
// specific song wasn't found in the queue
// songQueue is now empty
}
}
# 1 楼答案
您可以不断从队列中删除项目,直到找到要播放的特定歌曲,然后停止播放。结果将是一个队列,包含特定歌曲之后的所有项目,而之前没有任何项目
编辑:将变量更改为Java语法