In Java 7, the string substring changes to:
public String substring(int beginIndex) { if (beginIndex < 0) { throw new StringIndexOutOfBoundsException(beginIndex); } int subLen = value.length - beginIndex; if (subLen < 0) { throw new StringIndexOutOfBoundsException(subLen); } return (beginIndex == 0) ? this : new String(value, beginIndex, subLen); }
Therefore, every time you execute a subString with beginIndex NOT equal to 0, we have a new String object.
Ankush soni 09 Oct '15 at 11:54 on 2015-10-09 11:54
source share