Java String trim()

 Posted On  | Yashwant Chavan 

In this tutorial you will learn about Java String trim() method. This method is used to trim whitespace from the beginning and end of a string.

Refer below steps

  • String.trim() method removes leading and trailing whitespace from the string.

Java String.trim() method example

package com.technicalkeeda.app;

public class StringTrimExample {

    public static void main(String args[]) {
        String hello = "   hello   ";
        System.out.println("Before trim():- " + hello + " Length:- " + hello.length());
        System.out.println("After trim():- " + hello.trim() + " Length:- " + hello.trim().length());
    }
}

Output

Before trim():-    hello    Length:- 11
After trim():- hello Length:- 5


Promote your Blog, Website, or services on technicalkeeda.com, My paypal id: yashwantchavan@gmail.com

Payment will be accepted through paypal only.


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0300 seconds.