Given a String with white spaces, the task is to remove all white spaces from a string using Java built-in methods.
Input: str = " Geeks for Geeks " Output: GeeksforGeeks Input: str = " A Computer Science Portal" Output: AComputerSciencePortal
To remove all white spaces from String, use
replaceAll() method of String class with two arguments, i.e.
replaceAll("\\s", ""); where \\s is a single space in unicode
- Trim (Remove leading and trailing spaces) a string in Java
- Remove spaces from a given string
- Remove extra spaces from a string
- C++ Program to remove spaces from a string
- String containing first letter of every word in a given string with spaces
- Remove Leading Zeros From String in Java
- Remove all non-alphabetical characters of a String in Java
- Remove extra delimiter from a String in Java
- URLify a given string (Replace spaces is %20)
- Removing spaces from a string using Stringstream
- Move spaces to front of string in single traversal
- Python code to move spaces to front of string in single traversal
- Remove characters from the first string which are present in the second string
- Remove "b" and "ac" from a given string
- Remove duplicates from a given string
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.