Mega Code Archive

 
Categories / Java Tutorial / Data Type
 

To remove whitespace from the beginning and end of a string (but not the interior)

public class MainClass {   public static void main(String[] arg) {     String sample = "   This is a string   ";     String result = sample.trim();          System.out.println(">"+sample+"<");     System.out.println(">"+result+"<");   } } This is a string This is a string