Here you can find the source of substring(String text, int start, int end)
public static String substring(String text, int start, int end)
//package com.java2s; //License from project: Open Source License public class Main { public static String substring(String text, int start, int end) { if (text == null) return null; int spos = text.offsetByCodePoints(0, start); int epos = text.length() < end ? text.length() : end; return text.substring(spos, text.offsetByCodePoints(spos, epos - start)); }//from w w w . jav a 2 s .c om }