In this tutorial learn how you can write a program to remove all whitespaces from the String in java. We can use both float and double classes.
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.
Here is the code to remove all whitespaces from the String in Java programming.
//Write a program to remove all whitespaces from the String. import java.util.Scanner; public class Whitespace { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a sentence with a whitespaces"); String name = input.nextLine(); String word = name.replaceAll("\\s", ""); System.out.println("When we remove whitespaces from " + name + " we will get " + word + "."); input.close(); } }
This is how you can write a program to remove all whitespaces from the String in java programming. Comment below if you like our tutorial.