Java Scanner, taking user input from console into array list as separate words?

It may be simpler to use split for what you want.

It may be simpler to use split for what you want. // read a line, split into words and add them to a collection. Words.

AddAll(Arrays. AsList(input.nextLine(). Split("\\s+"))).

You could always use the Console class, like this: Console console = System.console(); System.out. Print("Enter a sentence: "); List words = Arrays. AsList(console.readLine().

Split("\\s+")); System.out. Println(words); The readline() method should take care of the \n issue. If you require a Scanner for the type reading capabilities, you can mix both classes: Scanner scanner = new Scanner(console.reader()); Hope this helps!

You could call input. HasNextLine and input. NextLine to get a line, and then create a new Scanner for the line you got and use the code that you have now.

Not the cheapest solution, but an easy way to implement it until you come up with a better one :-).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions