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.
- Regex Boundary Matchers in Java
- Java | Date format validation using Regex
- Count occurrences of a given character using Regex in Java
- Check if a string contains only alphabets in Java using Regex
- Get the first letter of each word in a string using regex in Java
- Extracting each word from a String using Regex in Java
- Print first letter of each word in a string using regex
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Removing elements between the two zeros
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.