void (@NotNull CharSequence src, char @NotNull [] dst, int srcOffset, int dstOffset, int len) { if (src instanceof CharArrayExternalizable) { ((CharArrayExternalizable)src).getChars(srcOffset, srcOffset + len, dst, dstOffset); return; } if (len >= GET_CHARS_THRESHOLD) { if (src instanceof String) { ((String)src).getChars(srcOffset, srcOffset + len, dst, dstOffset); return; } else if (src instanceof CharBuffer) { CharBuffer buffer = (CharBuffer)src; int i = buffer.position(); buffer.position(i + srcOffset); buffer.get(dst, dstOffset, len); buffer.position(i); return; } else if (src instanceof CharSequenceBackedByArray) { ((CharSequenceBackedByArray)src.subSequence(srcOffset, srcOffset + len)).getChars(dst, dstOffset); return; } else if (src instanceof StringBuffer) { ((StringBuffer)src).getChars(srcOffset, srcOffset + len, dst, dstOffset); return; } else if (src instanceof StringBuilder) { ((StringBuilder)src).getChars(srcOffset, srcOffset + len, dst, dstOffset); return; } } for (int i = 0, j = srcOffset, max = srcOffset + len; j < max && i < dst.length; i++, j++) { dst[i + dstOffset] = src.charAt(j); } }