I need a way to remove only the first space found in a string and then put the string in an array. For example
hello there. Hey.
I want that to be split like [hello][there. Hey]. I tried with
String [] s = str.split(" ")
by that will naturally remove all the spaces and create several strings. i just need 2. Can you please tell me how to do that ? Ether by regular expression or another way.
String [] s = str.split (" ", 2);should do the trick, documentation here.You may also want to consider using
\s+as the regex – it may split the string more intelligently.