StringUtil { public static String cut(String str, int threshold) { if (isEmpty(str) || str.length() <= threshold) { return str; } return str.substring(0, threshold); }  static boolean isEmpty(String str); static boolean isNotEmpty(String str); static void setIfPresent(String value, Consumer<String> setter); static String join(final char delimiter, final String... strings); static boolean substringMatch(CharSequence str, int index, CharSequence substring); static String cut(String str, int threshold); static String trim(final String str, final char ch);  }
@Test public void testCut() { String str = "aaaaaaabswbswbbsbwbsbbwbsbwbsbwbbsbbebewewewewewewewewewewew"; String shortStr = "ab"; Assert.assertEquals(10, StringUtil.cut(str, 10).length()); Assert.assertEquals(2, StringUtil.cut(shortStr, 10).length()); }