Java String stripLeading() Method Tutorial

In this section, we will learn what the String stripLeading() method is and how to use it in Java.

What is Java String stripLeading() Method?

The Java String stripLeading() method is used to remove any white space from the leading part (start) of a string value.


  • The method does not change the original value and just returns a new string as a result.
  • If the target string didn’t start with white spaces, the string itself will be returned instead.

Java stripLeading() Method Syntax:

public String stripLeading();

stripLeading() Method Parameters:

The method does not take an argument.

stripLeading() Method Return Value:

The return value of this method is a new string with its leading part cleared out of any white space.

stripLeading() Method Exceptions:

The method does not throw an exception.

Example: using String stripLeading() method

public class Main {
    public static void main(String[] args) {

        String input = "   hello   ";
        System.out.println("Input string length: " + input.length());
        String stripStr = input.stripLeading();
        System.out.println("Stripped string length: " + stripStr.length());


Input string length: 11

Stripped string length: 8

Top Technologies