Java - Write code to trim After Last Slash

Requirements

Write code to trim After Last Slash

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s/.com/";
        System.out.println(trimAfterLastSlash(str));
    }/* w ww. j  ava 2s .c  om*/

    public static String trimAfterLastSlash(String str) {
        if (str.lastIndexOf("/") > 0) {
            return str.substring(0, str.lastIndexOf("/"));
        }
        return str;
    }
}