Read User Input into an Array List (Java)

preview_player
Показать описание
This program shows you how to read user input into an array list and then output it.
Рекомендации по теме
Комментарии
Автор

Thanks, this snippet just ended my hour of troubleshooting: inputs.add(in.next());

yortex
Автор

how can I do this if I want to input a string in to an array list.??? tried everything.

mohamedjama
Автор

Hey thanks for the video. But is there any way to quit reading inputs without pressing done or any letter???? Pls reply

followyourdreams
Автор

If I am storing an Array of Strings how would I terminate it and count the number of String inputs from ArrayList?

kinghowardmaneclang
Автор

could someone please tell me how to do this, but for a text file instead of user input. Like ask user for the name of the file.

Beast
Автор

STRINGS!
Hi,
Took me a bit to figure out how to do it with strings:
ArrayList<String> towns = new ArrayList<>();
Scanner myInput = new Scanner(System.in);
towns.add(myInput.next());

code_kanga
Автор

How could you implement this without having to enter a string? I would also like to do this with an array of strings.

rileybarringer
Автор

What about inputing into an ArrayList in a for loop?

ryanw
Автор

I tried doing it with strings and for some reason when I input the word done there is no output

KaizoKitsune
Автор

Hi, great video. I have a question, the only way to get out of the while is to enter an invalid value? That is, because if I enter n numbers, when I get to the last number, it does not leave the while?

andresfelipe
Автор

The Code so you can copy and paste it:





import java.util.Scanner;
import java.util.ArrayList;

public class arrayTest2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

ArrayList<Double> inputs = new ArrayList<Double>();
System.out.println("Enter some numbers: ");
while (in.hasNextDouble()) {
inputs.add(in.nextDouble());
}
System.out.println(inputs);
}
}

TheRealCorcra
Автор

Why is this not working for me .... array list just keep saying some bullsh*t and not stuff i put inside.

vinto