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));
    }//from   ww  w . java2  s .  c  o  m

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