I have a string like
String str = "My name is Monda"
How can I achieve a string like
str = "MynameisMonda"
You can use the replaceAll() function.
For your case:
replaceAll("\\s","")
where \s means any whitespace (such as a space character).
You just need this function. replaceAll()
str.replaceAll("\\s","")
\s = Anything that is a space character (including space, tab characters etc)
You need to escape the backslash if you want \s to reach the regex engine, resulting in \s. Like wise we use :-
\S = Anything that isn't a space character (including both letters and numbers, as well as punctuation etc)
\w = Anything that is a word character
\W = Anything that isn't a word character (including punctuation etc)