To replace blanks in a string in Java you can use the following snippet.

Sample Java

public static String RemoveBlanks(String input) {  
    return input.replaceAll("\\s", "");  
} 

2 thought on “How to replace blanks in a string in Java”

Leave a Reply