Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
What is the shortest method to create a String array out of every word in sentence String in JAVA?

1 Answer

0 votes
by (11.3k points)
edited by

For this, we use split() function in JAVA. Suppose you have a 

String a="I am hello";

If you want to store String a as a 3 element array with the elements, "I","am" and "hello", you simply use:

String arr[] = a.split(" ");

This would create an array that is much easier to operate upon.

Browse Categories

...