我是JAVA和Netbeans的新手,這是我必須做的:
用戶可以在輸入框中輸入標題CD,然後通過按刪除按鈕。如果集合中不存在該CD,則可以在發件箱中顯示一條消息來說明這一點。
這是我做了什麼:集合的BinarySearch不起作用
ArrayList <String> songs = new ArrayList();
Collections.addAll(songs, "Metric - Fantasies", "\nBeatles - Abbey Road", "\nPearl Jam - Ten", "\nDoors - Alive", "\nThe Rolling Stones - Gimme Shelter\n");
int remove = Collections.binarySearch(songs, artistinput.getText());
if (remove < 0)
{
output.setText("That CD does not exist in the collection, please try again");
}
else if (remove >= 0)
{
boolean delete=songs.remove(artistinput.getText());{
output.setText("Original Songs \n" +delete);
這是我還沒有想通了該計劃的一部分。這不起作用,因爲每次我輸入歌曲並按'刪除'時它只顯示output.setText("That CD does not exist in the collection, please try again");
。任何幫助表示感謝,並提前謝謝你!
您的歌曲沒有排序。它包含換行符'\ n',爲什麼?另外,是[這](http://stackoverflow.com/questions/40835111/difficulty-with-collections-binarysearch/40835224?noredirect=1#comment68887977_40835224)你呢? –
醫生不太可能會從輸入中用'\ n'獲得文本。 –
多數民衆贊成那不是我即使我們的問題是有點相同 –