Logo

Programming-Idioms

  • JS
  • Elixir
  • Java

Idiom #279 Read list of strings from the standard input

Read all the lines (until EOF) into the list of strings lines.

import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
List<String> lines = new ArrayList<>();
Scanner in = new Scanner(System.in);
while(in.hasNextLine())
    lines.add(in.nextLine());
with Ada.Text_IO;
with Ada.Containers.Indefinite_Vectors;
declare
   package String_Vectors is new
      Ada.Containers.Indefinite_Vectors
         (Index_Type => Positive, Element_Type => String);
   use String_Vectors, Ada.Text_IO;
   Lines : Vector;
begin
   while not End_Of_File loop
      Lines.Append (Get_Line);
   end loop;
end;

New implementation...