How to insert ArrayList into While-condition?


Wed Apr 01 2020 11:31:57 GMT+0000 (Coordinated Universal Time)

Saved by @SunLoves #java #java #arraylists #while-loops #equala

List<String> songList = new ArrayList<>();
songList.add("Some song"); //Repeat until satisfied

System.out.println("\n\tWelcome! Please choose a song!");
String songChoice = scan.nextLine();
while (!songList.contains(songChoice)) {
    //Do stuff when input is not a recognised song

A possible solution is to create an ArrayList, populate it with all the strings and check if the input matches one of those strings.