[Solved] How to get a multiple-line input from a user in Java and then store the input in an array of type string where every line is an element of the array [duplicate]


With the help of Scanner class you can take input from cmd and store each line into Array of String or In ArrayList collection.

public static void main(String[] args) {

    ArrayList<String> in = new ArrayList<String>();
    Scanner s = new Scanner(System.in);

    while (s.hasNextLine()) {
        String line = s.nextLine();
        in.add(line);

        if (line != null && line.equalsIgnoreCase("END")) {
            System.out.println("Output list : " + in);
            break;
        }

    }

}

solved How to get a multiple-line input from a user in Java and then store the input in an array of type string where every line is an element of the array [duplicate]