0
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?

1
  • .split() returns a String array, so it is not necessary to instantiate one yourself Commented Oct 23, 2019 at 17:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.