How to Remove white spaces from given String or Char Array

How to Remove white spaces from given String or Char Array
SOURCE : RemoveWhiteSpace.java

public class RemoveWhiteSpace {

public static void main(String[] args) {

char[] data = { 'a', 'a', 'b', ' ', ' ', 'c', ' ', 'd', 'e' };

String s = new String(data);
String a = s.replaceAll(",", "").replaceAll(" ", "");
System.out.println(a.toString());

}

}


INPUT

char[] data = { 'a', 'a', 'b', ' ', ' ', 'c', ' ', 'd', 'e' }



OUTPUT

aabcde






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment