Here you can find the source of substr(String src, int beginIndex, int endIndex)
public static String substr(String src, int beginIndex, int endIndex)
//package com.java2s; public class Main { public static String substr(String src, int beginIndex, int endIndex) { String dest = ""; if (src == null) { return dest; }//from w w w .jav a2 s . co m byte[] srcByte = src.getBytes(); byte[] destByte = null; int srclen = srcByte.length; if (srclen <= beginIndex || beginIndex >= endIndex) { return ""; } if (srclen >= endIndex) { destByte = new byte[endIndex - beginIndex]; System.arraycopy(srcByte, beginIndex, destByte, 0, endIndex - beginIndex); dest = new String(destByte); return dest; } else { destByte = new byte[srclen - beginIndex]; System.arraycopy(srcByte, beginIndex, destByte, 0, srclen - beginIndex); dest = new String(destByte); return dest; } } }