Drop Down

Monday, February 4, 2019

RemoveSpace

package interview;
//Remove white space
public class RemoveSpace {

public static void main(String[] args)
{
//*******************************************  
  String s1 = "remove white space";
  String s2 = s1.replaceAll("\\s","");
  String s4 = s1.replaceAll("\\s","~");
  System.out.println(s2);
  System.out.println(s4);
//*******************************************
  String s3 = "remove white space";
  char[] ch = s3.toCharArray();
  StringBuffer sb = new StringBuffer();
  for(char c : ch)
  {
  if (c!=' ')
  {
  sb = sb.append(c);
  }
  }
  System.out.println(sb);                                                                                                            
}

}

No comments:

Post a Comment

Java 8 Notes Pics