Java - Write code to trim Suffix

Requirements

Write code to trim Suffix

Demo

//package com.book2s;

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

    public static final String trimSuffix(final String text,
            final String suffix) {
        if (text == null) {
            return null;
        }
        if (suffix == null) {
            return text;
        }
        if (text.endsWith(suffix)) {
            return text.substring(0, text.length() - suffix.length());
        }
        return text;
    }
}