Tutorials

Java String Methods


String trim() method


In java String trim( ) method removes the space from both the front and back of the given String, if any exists.

 

Example:


public class TrimDemo {

      public static void main(String[] args) {

            String str = " Rajneesh ";

            System.out.println(str + "Shukla");
            System.out.println(str.trim() + "Shukla");

      }

}

 

OUTPUT:

 Rajneesh Shukla

RajneeshShukla



Please Share this page
Views : 52