In this example we will show the method to remove spaces in a string in Java.
Source Code
package com.beginner.examples;
public class RemoveSpaces {
public static void main(String[] args) {
String str = "ABC DE F";
str = str.replaceAll(" +", ""); // remove spaces
System.out.println(str);
}
}
Output:
ABCDEF