Here you can find the source of substr(String str, int beginIndex, int endIndex)
public static String substr(String str, int beginIndex, int endIndex)
//package com.java2s; //License from project: Open Source License public class Main { public static String substr(String str, int beginIndex, int endIndex) { if (isBlank(str)) { return ""; }/*from w w w .j a v a 2 s. c om*/ if (endIndex == -1) { return str.substring(beginIndex); } if (endIndex > str.length()) { endIndex = str.length(); } return str.substring(beginIndex, endIndex); } public String substr(String str, int beginIndex, int endIndex, String endMark) { if (isBlank(str)) { return ""; } if (endIndex == -1) { return str.substring(beginIndex); } if (endIndex > str.length()) { endIndex = str.length(); } String restr = str.substring(beginIndex, endIndex); if (endIndex < str.length()) { restr = restr + endMark; } return restr; } public static boolean isBlank(String str) { if (isEmpty(str)) return true; for (int i = 0; i < str.length(); i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; } public static boolean isEmpty(String str) { return str == null || str.length() == 0; } }