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));
    }/*  ww w  .jav  a2s  .  c o  m*/

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