Trying to write a short method so that I can parse a string and extract the first word. I have been looking for the best way to do this.
I assume I would use s
s
like this:
final String str = "This is a long sentence"; final String[] arr = str.split(" ", 2); System.out.println(Arrays.toString(arr));
arr[0] is the first word, arr[1] is the rest
arr[0]
arr[1]