Removing duplicate whitespace using regular expression

Written by coregps on December 14th, 2007 in Java.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Just a simple note about how to remove duplicate whitespace using regular expression in java.

public class Test {
    public static void main(String[] args) {
        String str = "Hello      World!";
		System.out.println(str.replaceAll("\s+", " "));
	}
}

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • De.lirio.us
  • feedmelinks
  • Furl
  • LinkaGoGo
  • scuttle
  • Shadows
  • Smarking
  • Reddit
  • Spurl
  • YahooMyWeb
  • connotea
  • Technorati
  • Netvouz
  • Fark
  • DZone
  • Netscape
  • Simpy
  • NewsVine
  • Slashdot

Leave a Reply



Site Navigation