Java String Class strip() Method With Examples Last Updated : 02 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 string, with all leading and trailing white space removed Syntax: String strippedString = string.strip() stripLeading() Method: It returns a string, with all leading white space removed. Syntax: String leadingStripString = string.stripLeading() stripTrailing() Method: It returns a string, with all trailing white space removed. Syntax: String trailedStripString = string.stripTrailing() Example: Java // Java Program to demonstrate the use of the strip() // method,stripLeading() method,stripTrailing() method public class GFG { public static void main(String[] args) { String str = " Geeks For Geeks Internship ! "; // removing leading and // trailing white spaces System.out.println(str.strip()); // removing leading white spaces System.out.println(str.stripLeading()); // removing trailing white spaces System.out.println(str.stripTrailing()); } } Output: Geeks For Geeks Internship ! Geeks For Geeks Internship ! Geeks For Geeks Internship ! Comment More infoAdvertise with us Next Article How to Zip and Unzip Files in Java? L le0 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Strings +1 More Practice Tags : JavaJava-Strings Similar Reads String Class stripLeading() Method in Java With Examples 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() 2 min read Java String startsWith() and endsWith() Methods With Examples In Java, the startsWith() and endsWith() methods of the String class are used to check whether a string begins or ends with a specific prefix or suffix, respectively.Example:This example demonstrates the usage of the startsWith() and endsWith() methods in Java.Java// Java Program to demonstrate // s 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 How to Zip and Unzip Files in Java? In Java Programming we have a lot of features available for solving real-time problems. Here I will explain how to Zip files and How to Unzip files by using Java Programming. Mostly zip and unzip files are used for zip the files for save storage, easy to share, and other purposes. In this article, w 3 min read How to get Slice of a Stream in Java A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. Slice of a Stream means a stream of elements that exists in a specified limit, from the original stream. Examples: Input: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Output: [15, 16, 17 6 min read Java Program to Trim Leading and Trailing Spaces from a String In Java, the trim() method is used to remove leading and trailing spaces from a string. This method does not remove spaces between words but it eliminates unnecessary spaces at the beginning and end of the string. The trim() method is defined under the String class in the java.lang package. It check 1 min read Like