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.



public class TrimDemo {

      public static void main(String[] args) {

            String str = " Rajneesh ";

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





 Rajneesh Shukla


Please Share this page
Views : 137
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!