Woops, sloppy! Thanks :)
I just learned the join method, so I decidied it would be cool to use it in this problem. Thank you for your help :]
Split/Join is significantly less efficient than replace.
Always use curly braces on if statements for readability and maintainability.
toCharArray() creates a copy of the string. You should always avoid this method.
Do not use toCharArray(), it causes the string to be copied, where a copy is not necessary.
n >= arr.length
Doesn't work for all test cases.
Needs a test case where some words are a substring of previous words.
Example: "starborn star"
Fails for case "starborn star"
This comment is hidden because it contains spoiler information about the solution
Simple one liner using the Streams API
Class and method should be marked public. They have package level access by default.
One line version using streams. Still too many array locations, see my other solution for how to avoid array allocations.
This solution uses prefix recursion. Use tail recursion to collapse the stack depth.