Here you can find the source of substring(final String s, int startIndex, int endIndex)
Parameter | Description |
---|---|
s | any string |
startIndex | start index (maybe greater that endIndex) |
endIndex | required end index (may greater that the string itself) |
public static String substring(final String s, int startIndex, int endIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**//from www . j a v a2 s .c om * a 'safe' @link {@link String#substring(int, int)} that does not throw exceptions when indexes are false. * * @param s * any string * @param startIndex * start index (maybe greater that endIndex) * @param endIndex * required end index (may greater that the string itself) * @return substring */ public static String substring(final String s, int startIndex, int endIndex) { startIndex = Math.min(s.length(), Math.max(0, startIndex)); endIndex = Math.min(s.length(), Math.max(0, endIndex)); return s.substring(Math.min(startIndex, endIndex), Math.max(startIndex, endIndex)); } }