G
G
genrixxx2021-10-26 14:57:23
Java
genrixxx, 2021-10-26 14:57:23

How to end a dynamic array?

I have an array to which I add elements and I need to stop it with an enter. How to do it?

packagecom.company;
import java.util.ArrayList;
import java.util.Scanner;

public class name {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
ArrayList arguments = new ArrayList();
arguments.add(input.next());
while (input.hasNext()) {
arguments.add(input.next());
}
System.out.println(arguments);
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question