Java - Write code to get substring After Last delimiter

Requirements

Write code to get substring After Last delimiter

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String string = "book2s.com";
        String delimiter = "o";
        System.out.println(substringAfterLast(string, delimiter));
    }//from  w w w .j  a  v  a 2s.  c o  m

    public static String substringAfterLast(String string, String delimiter) {
        final int index = string.lastIndexOf(delimiter);
        if (index == -1 || string.endsWith(delimiter)) {
            return "";
        }
        return string.substring(index + 1);
    }
}

Related Exercise