Java - Write code to strip Path ending \

Requirements

Write code to strip Path ending \

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String filename = "book2s.com\\";
        System.out.println(stripPath(filename));
    }//  w ww  . j  a  va 2s.c  om

    public static String stripPath(String filename) {
        int index = filename.lastIndexOf("\\");
        if (index == -1)
            return (filename);
        return (filename.substring(index + 1));
    }
}