Remove whitespace in Java string.

Java 8Object Oriented ProgrammingProgramming

You can remove empty spaces from a string using the replace() method of the String class

Example

Live Demo

public class StringwhiteSpace {
   public static void main(String args[]){
      String str = "Welcome to Tutorialspoint";
      str = str.replace(" ", "");
      System.out.println(str);
   }
}

Output

WelcometoTutorialspoint
raja
Updated on 26-Feb-2020 08:14:34

Advertisements