How do I get up to the first n characters of a string in Java without doing a size check first (inline is acceptable) or risking an IndexOutOfBoundsExcept
n
IndexOutOfBoundsExcept
Apache Commons Lang has a StringUtils.left method for this.
String upToNCharacters = StringUtils.left(s, n);