Java - Write code to strip from the End of a string

Requirements

Write code to strip string End.

abc becomes ab

Hint

Use while statement to check the ends.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        String stripChars = "com";
        System.out.println(stripEnd(str, stripChars));
    }//w  ww .j  a  v a 2s.  c o  m

    public static final int INDEX_NOT_FOUND = -1;

    public static String stripEnd(String str, String stripChars) {
        int end;
        if (str == null || (end = str.length()) == 0) {
            return str;
        }

        if (stripChars == null) {
            while ((end != 0)
                    && Character.isWhitespace(str.charAt(end - 1))) {
                end--;
            }
        } else if (stripChars.length() == 0) {
            return str;
        } else {
            while ((end != 0)
                    && (stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND)) {
                end--;
            }
        }
        return str.substring(0, end);
    }
}