Sunday, August 19, 2018

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




package com.rwsfs.test;

public class Test2 {

public static void main(String[] args) {
String s="Good Morning Mumbai";
StringBuilder sb=new StringBuilder();
for(int i=0;i<s.length();i++){
if(s.charAt(i)!=' '){
sb.append(s.charAt(i));
}
}
System.out.println("Original String = "+s);
System.out.println("\nNew String = "+sb);
}
}





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

0 Comment to "How do you remove all white spaces from a string in java?"

Post a Comment