How to remove the all white spaces from a String in Java?
You can remove all white spaces from the String by Using replaceAll() method . For Example- public static void main(String[] args) {
String str= " Hello world Hello ";
//Call the replaceAll method
str= str.replaceAll(“\s”, “”); //where \s is a single space in unicode
System.out.println(str);