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 : 84
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!