I am trying to achieve this using the String.split function in Java but doesn't seem to find an elegant solution. The number of blank space between each character or word is fixed.
String original = "H E L L O W O R L D" String finalWord = original.split(); System.out.println(finalWord); HELLO WORLD Basically, the number of white space between each alphabet is fixed e.g. 2 and the number of white space between word is also fixed e.g. 4.
How can I achieve that using Java?
H(space)(space)E(space)(space)L(space)(space)L(space)(space)O(space)(space)(space)(space)W(space)(space)O(space)(space)R(space)(space)L(space)(space)D
into
HELLO(space)WORLD
Hope it's understandable!
4 spacesbysingle space. Then replace2 spaceswithblank space.splitneeds an argument, etc.) indicates that you didn't try too hard to find the solution on your own.