String Class stripLeading() Method in Java With Examples Last Updated : 05 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report String Class stripLeading() method is used to strip leading whitespaces from the string i.e stripLeading() method removes all the whitespaces only at the starting of the string. Example: Input: String name = " kapil "; System.out.println("#" + name + "#); System.out.println("#" + name.stripLeading()); Output: # kapil # #kapil # // Leading whitespaces are removed Syntax: public String stripLeading()Returns: The string after removing all the whitespaces at the start of the string. Note: Like the stripTrailing() method in java, we have strip() (removes leading and trailing whitespace) and stripLeading() (removes the only leading whitespace). Below is the implementation of the problem statement: Java // Java program to demonstrate the usage of // stripLeading() method in comparison to // other methods class GFG { public static void main(String[] args) { // creating a string String str = " Hello, World "; // print the string without any function System.out.println("String is"); System.out.println("#" + str + "#"); System.out.println(); // using strip() method System.out.println("Using strip()"); System.out.println("#" + str.strip() + "#"); System.out.println(); // using stripLeading() method System.out.println("Using stripLeading()"); System.out.println("#" + str.stripLeading() + "#"); System.out.println(); // using stripTrailing() method System.out.println("Using stripTrailing()"); System.out.println("#" + str.stripTrailing() + "#"); } } Output: String is # Hello, World # Using strip() #Hello, World# Using stripLeading() #Hello, World # Using stripTrailing() # Hello, World# Comment More infoAdvertise with us Next Article How to Remove all White Spaces from a String in Java? K kapilnama1998 Follow Improve Article Tags : Java Java Programs Java-Strings Practice Tags : JavaJava-Strings Similar Reads Java String Class strip() Method With Examples Java String Class strip() method returns a string that provides a string with all leading and trailing white spaces removed. This method is similar to the String.trim() method. There are basically 3 methods by which we can remove white spaces in a different manner. strip() Method: It returns a strin 1 min read How to Split a String into Equal Length Substrings in Java? In Java, splitting a string into smaller substrings of equal length is useful for processing large strings in manageable pieces. We can do this with the substring method of the loop. This method extracts a substring of the specified length from the input string and stores it in a list.Example:In the 3 min read How to Split a String in Java with Delimiter? In Java, the split() method of the String class is used to split a string into an array of substrings based on a specified delimiter. The best example of this is CSV (Comma Separated Values) files.Program to Split a String with Delimiter in JavaHere is a simple program to split a string with a comma 2 min read How to Remove all White Spaces from a String in Java? In Java, to remove all white spaces from a String, there are several ways like using replaceAll() or manual iteration over characters. In this article, we will learn how to remove all white spaces from a string in Java.Example:We will use the replaceAll() method with the regex pattern "\\s" to remov 3 min read Java Program to Replace Multiple Characters in a String In this program, we will be discussing various methods for replacing multiple characters in String. This can be done using the methods listed below: Using String.replace() methodUsing replaceAll() method Using replaceFirst() method Method 1: Using String.replace() method This method returns a new st 3 min read How to Remove Duplicates from a String in Java? Working with strings is a typical activity in Java programming, and sometimes we need to remove duplicate characters from a string. In this article we have given a string, the task is to remove duplicates from it. Example Input: s = "geeks for geeks"Output: str = "geks for" Remove Duplicates From a 2 min read Like