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
Published on 12-Feb-2018 06:55:48
Advertisements