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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.