Java examples for Language Basics:String
Use the String trim() method to eliminate the whitespace.
public class Main { public static void main(String[] args){ String myString = " This is a String that contains whitespace. "; //from w ww . j av a 2s. c om System.out.println(myString); System.out.println(myString.trim()); } }