This post will discuss how to remove a prefix from a string in Java.

1. Using String.substring() method

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

Download  Run Code

Output:

natural

2. Using String.split() method

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

Download  Run Code

Output:

natural

3. Using Apache Commons Lang

We can also use the Apache Commons Lang library, which has the removeStart() utility method in the StringUtils class, which does the job and handles NullPointerException.

Download Code

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