Java Tutorial

Java String Strip Method

TGTeam GyaniPanditSeptember 12, 20221 min read

Java String Strip

Well, with this method, we can cut the whitespaces from the start and the end of the string. Have a look at the program below to understand the thing. This works similarly to the trim method.

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

So, executing the above program clearly gives us the string without the whitespaces in this case. Now let’s implement the other methods related to strip, which are stripLeading, and stripTrailing.

Turn reading into skillsCertificate courses in AI, Data Science and programming.
Explore Courses