Java - Write code to cut a string in the middle

Requirements

Write code to cut a string in the middle

Demo

//package com.book2s;

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

    public static final String EMPTY_STRING = "";

    public static String mid(String str, int pos, int len) {
        if (str == null) {
            return null;
        }

        if ((len < 0) || (pos > str.length())) {
            return EMPTY_STRING;
        }

        if (pos < 0) {
            pos = 0;
        }

        if (str.length() <= (pos + len)) {
            return str.substring(pos);
        } else {
            return str.substring(pos, pos + len);
        }
    }

}