This question has already been answered:

How to count several (the number can be different and we can NOT set it) lines from the console in Java?

Reported as a duplicate by the participants Mikhail Vaysman , rjhdby , Pavel Mayorov , aleksandr barakin , Duck Learns to Take Cover 5 Jul '17 at 14:31 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    List<String> input = new ArrayList(); Scanner scan = new Scanner(System.in); while(true){ String current = scan.nextLine(); if(current.equals(""))break; input.add(current); } 

    Input is terminated when an empty string is entered

    • You yourself answered this question. why produce duplicates? - Mikhail Vaysman
    • The human memory tool is dark and poorly understood. Here I, for example, do not remember at close range, to answer this question already. Which is not surprising in view of its elementary nature and the time spent on response - rjhdby
    • If you look at the column on the right - Related , you will see similar questions there. It will help you to remember. and this answer should be deleted. - Mikhail Vaysman
    • Yes, the link then I certainly went already. I mean that at the time of the answer I didn’t remember at all that I had already responded to this - rjhdby