Java - Write code to cut the string from right

Requirements

Write code to cut the string from right

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        int len = 2;
        System.out.println(right(str, len));
    }/*from w w  w  .  ja  v  a2  s .c o  m*/

    private static final String EMPTY = "";

    public static String right(String str, int len) {
        if (str == null) {
            return null;
        }
        if (len < 0) {
            return EMPTY;
        }
        if (str.length() <= len) {
            return str;
        }
        return str.substring(str.length() - len);
    }
}