Java - Write code to trim Last Slash

Requirements

Write code to trim Last Slash

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com/";
        System.out.println(trimLastSlash(str));
    }//from  ww  w . ja v a  2s .co m

    public static String trimLastSlash(String str) {
        if (str.endsWith("/")) {
            return str.substring(0, str.length() - 1);
        }
        return str;
    }
}