print
Advertisment
Advertisment

Remove All White Spaces From String

Example 2

 public class removeWhiteSpace {    
    public static void main(String[] args) {    
            
        String str1="Remove white spaces";    
            
        //Removes the white spaces using regex    
        str1 = str1.replaceAll("\\s+", "");    
            
        System.out.println("String after removing all the white spaces : " + str1);    
    }    
}       

Output :

 
   
String after removing all the white spaces: Removewhitespaces
   
Advertisment
Advertisment
arrow_upward