Sunday, August 19, 2018

How do you remove all white spaces from a string in java?




package com.rwsfs.test;

public class Test {

public static void main(String[] args) {
String s="My name is khan and i am not a terrorist";
String newString=s.replaceAll("\\s","");
System.out.println("Original String = "+s);
System.out.println("New String = "+newString);
}
}

How do you remove all white spaces from a string in java?
How do you remove all white spaces from a string in java?

Share this

2 Responses to "How do you remove all white spaces from a string in java?"