In this quick article, we’ll explore how to remove a suffix from a string in Java.

1. Using String.substring() method

The recommended approach is to make use of the substring() method of the String class, as shown below:

Download  Run Code

Output:

Java

2. Using String.split() method

Another plausible way is to split the given string around the given suffix using the split() method of the String class and return the first value of the string array.

Download  Run Code

Output:

Java

3. Using Apache Commons Lang

You might also want to look at the StringUtils class of the Apache Commons Lang library, which provides the removeStart() utility method that does the job.

Download Code

That’s all about removing a suffix from a Java String.