Here you can find the source of removeSpaces(String orig)
public static String removeSpaces(String orig)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**// w w w. j av a 2s.com * xxx yyy zzz becomes xxxyyyzzz. */ public static String removeSpaces(String orig) { StringTokenizer st = new StringTokenizer(orig, " "); StringBuffer sb = new StringBuffer(orig.length()); while (st.hasMoreTokens()) { sb.append(st.nextToken()); } if (sb.toString().length() == 0) return orig; return sb.toString(); } }