StringUtils substringAfter() Example in Java

In this post, we will see org.apache.commons.lang3.StringUtils substringAfter() example in Java.

import org.apache.commons.lang3.StringUtils;

public class StringUtilsExample {
    public static void main(String[] args) {
        String str = "Hello, world!";
        String substr = StringUtils.substringAfter(str, ",");
        System.out.println(substr); // Output:  world!
    }
}

Output is –

In this example, we import the StringUtils class from the Apache Commons Lang library, and then define a string str that contains the text “Hello, world!”. We then use the substringAfter() method to extract the substring after the comma, which is ” world!”, and store it in the substr variable. Finally, we print the substr variable to the console, which outputs ” world!”.

We need to add the below dependency in pom.xml to use org.apache.commons.lang3.StringUtils substringAfter() method. We can download the apache-commons maven dependency from here.

pom.xml changes

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>

Seed docs here.

That’s all about StringUtils substringAfter() example in Java.

Related post.