Reputation: 11
public static void main(String[] args)
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in);
String[] a = new String[]{br.readLine().split("\\s")};
}
I'm getting errors here. Is there any direct way to convert the line into array of strings?
Upvotes: 0
Views: 94
Reputation: 5175
split
returns an array
of strings so you can simply initialize a
as:
String[] a = br.readLine().split("\\s");
String[] myArray = new String[] {...}
is what is known as an array literal, and the values need to be known before the code runs.
Upvotes: 1