Welcome to the World of Online Learning:
Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a Java Program to Remove All Whitespaces from a String
PROGRAM: Java Program to Remove All Whitespaces from a String
/*Java Program to Remove All Whitespaces from a String*/
1: Program to Remove All Whitespaces
public class Whitespaces {
public static void main(String[] args) {
String sentence = “T his is b ett er.”;
System.out.println(“Original sentence: ” + sentence);
sentence = sentence.replaceAll(“\\s”, “”);
System.out.println(“After replacement: ” + sentence);
}
}
2: Take string from users and remove the white space
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// create an object of Scanner
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the string”);
// take the input
String input = sc.nextLine();
System.out.println(“Original String: ” + input);
// remove white spaces
input = input.replaceAll(“\\s”, “”);
System.out.println(“Final String: ” + input);
sc.close();
}
}