private static CharSequence substr ( CharSequence str , int s , int e ) { return ( s >= e ) ? null : CharBuffer . wrap ( str , s , e ) ; }
The substring method will create a copy of the substring in JDK 8 and probably newer versions . To reduce the number of allocations we use a char buffer to return a view with just that subset .