Modification of existing method to return an array of strings instead of printing them

Hi,

I have the following method which I would like to modify so the method returns the words as an array of strings rather than printing them which happens at the moment.

public static String test()
{
String str = "This is a string object";
String[] words = str.split (" ");
for (int i=0; i < words.length; i++)
{
 System.out.println (words[i]);
}
}
sjsharp80Asked:
Who is Participating?
 
cmalakarConnect With a Mentor Commented:

public static String[] test()
{
String str = "This is a string object";
String[] words = str.split (" ");
return words;
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.