Jordan
Jordan

Reputation: 305

Java Reading input from a text file that has multiple columns

This is an example of the text that I need to manipulate:

YEAR (space) MONTH (space) NAME (space)

YEAR (space) MONTH (space) NAME (space)

YEAR (sapce) MONTH (space) NAME (space)

YEAR (sapce) MONTH (space) NAME (space) ...

How would one go about creating an array using only the values in one column? e.g the second column (months) or the last column (names)

Upvotes: 2

Views: 1716

Answers (3)

Alberto Solano
Alberto Solano

Reputation: 8227

Read this answer. See also the split method of String Class in Java Api.

Upvotes: 0

TofuBeer
TofuBeer

Reputation: 61526

Take a look at the java.util.Scanner class, specifically the hasNext and next methods.

Upvotes: 3

miki
miki

Reputation: 695

read each line and split on space, and reformat the array..

read each line and use a substring to add to the array..

read each line and use regular expression..

Upvotes: 4

Related Questions