Scanner scan = new Scanner(System.in);
System.out.println("Enter the names of each song in the DJ's playlist: ");
System.out.println("When finished, enter done.");
ArrayList <String> NamesOfSongs = new ArrayList<>();
boolean loop = true;
while(loop)
{
String input = scan.nextLine();
if (input.equals("done"))
{
break;
}
else
{
NamesOfSongs.add(scan.nextLine());
}
}
System.out.println(NamesOfSongs);
}
Input strings need to be added to the ArrayList until user enters "done" and the method is finished.
Results in: (after I enter 3 strings and done TWICE)
Enter the names of each song in the DJ's playlist:
When finished, enter done.
jjjj
kkkkk
iiii
done
done
[kkkkk, done]