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.
Input: String name = " kapil "; System.out.println("#" + name + "#); System.out.println("#" + name.stripLeading()); Output: # kapil # #kapil # // Leading whitespaces are removed
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:
String is # Hello, World # Using strip() #Hello, World# Using stripLeading() #Hello, World # Using stripTrailing() # Hello, World#
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.