-3

Can someone please tell me how to split this string?

Sample Input

String in = "Erin M Haggens";

Desired Output

String str1 = "Erin";
String str2 = "M";
String str3 = "Haggens";
entpnerd
  • 10,049
  • 8
  • 47
  • 68

1 Answers1

1

Use the String.split() method.

The code myStr.split("\\s+") should work for you. Then you can use each element of the returned array as one of your outputted strings.

entpnerd
  • 10,049
  • 8
  • 47
  • 68