CharSequences { public static CharSequence getPrefix(CharSequence input, int endIndex) { if (endIndex > input.length()) { return input; } return input.subSequence(0, endIndex); } CharSequences(); static Iterable<CharSequence> generateSuffixes(final CharSequence input); static Iterable<CharSequence> generatePrefixes(final CharSequence input); static CharSequence getCommonPrefix(CharSequence first, CharSequence second); static CharSequence getSuffix(CharSequence input, int startIndex); static CharSequence getPrefix(CharSequence input, int endIndex); static CharSequence subtractPrefix(CharSequence main, CharSequence prefix); static CharSequence concatenate(final CharSequence first, final CharSequence second); static CharSequence reverse(CharSequence input); static CharSequence fromCharArray(final char[] characters); static char[] toCharArray(CharSequence charSequence); static String toString(CharSequence charSequence);  }
@Test public void testGetPrefix() throws Exception { Assert.assertEquals("", CharSequences.getPrefix("BANANA", 0)); Assert.assertEquals("BAN", CharSequences.getPrefix("BANANA", 3)); Assert.assertEquals("BANANA", CharSequences.getPrefix("BANANA", 6)); Assert.assertEquals("BANANA", CharSequences.getPrefix("BANANA", 7)); }