The following programs demonstrates how to remove the white spaces using matcher.replaceAll(String replacement) method of Util.regex.Pattern class.
The java.util.regex.Matcher.replaceAll(String replacement) method replaces every subsequence of the input sequence that matches the pattern with the given replacement string.
Declaration: public String replaceAll(String replacement)
Parameters: replacement – The replacement string.
Return Value:The string constructed by replacing each matching subsequence by the replacement string, substituting captured subsequences as needed.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Program to check if a String in Java contains only whitespaces
- Extracting each word from a String using Regex in Java
- Get the first letter of each word in a string using regex in Java
- Java | Date format validation using Regex
- Check if a string contains only alphabets in Java using Regex
- Count occurrences of a given character using Regex in Java
- Print first letter of each word in a string using regex
- How to validate an IP address using ReGex
- Regex Boundary Matchers in Java
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Removing Pages from a PDF Document using Java
- Removing last element from ArrayList in Java
- Removing elements between the two zeros
- Accessing Grandparent’s member in Java using super
- Using underscore in Numeric Literals in Java
- Producer-Consumer solution using threads in Java
- Copying file using FileStreams in Java
- Swap two Strings without using third user defined variable in Java
- File handling in Java using FileWriter and FileReader
- Simple Calculator using TCP in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.