Skip to content
Advertisement

Read next word in java

I have a text file that has following content:

JavaScript

I read the text file and iterate through the lines:

JavaScript

Each line has two words. Is there any method in java to get the next word or do I have to split the line string to get the words?

Advertisement

Answer

You do not necessarily have to split the line because java.util.Scanner’s default delimiter is whitespace.

You can just create a new Scanner object within your while statement.

JavaScript
Advertisement