StripLeading Method

Java String StripLeading

Well, as the name says, this method is going to cut the leading whitespaces, which means the whitespaces that are at the start.

Let’s have an example program to demonstrate the same –

public class StringMethods {
public static void main(String[] args) {
String spaces = ” Java “;
System.out.println(spaces.stripLeading());
}
}

Well, if you try running the program, we can find that the leading whitespaces(the whitespaces from the start) are removed now, but the trailing whitespaces(the ending whitespaces) are still there. In order to get rid of only whitespaces from the end, you can use another method –