I tried to do some String manipulation to play around with the methods available and I noticed that when I used the replaceAll("\\s+","")
method to remove whitespaces in a String, it failed to do it.
System.out.print("Enter a word: ");
String word = scanner.next();
String cleansed = word.replaceAll("\\s+","");
char[] letters = cleansed.toCharArray();
for(char c : letters){
System.out.print(c+" ");
}
When I go to the console and do something like,
Enter a word : I am entering some word.
The output I get on the console is I
which seems to be dropping all other String
values after the space.
What am I missing here?
I play around with different methods when there's nothing to do. So right now I just wonder why it's not working as expected.
I'd appreciate any help.
Thank you.