StringUtil { public static String subHead(String str, int maxLen){ if(str == null || str.length() <= maxLen){ return str; } return str.substring(0, maxLen); }  static String subHead(String str, int maxLen); static String toString(Object obj); static String randomString(int length); static String join(String split, String... args); static String join(String split, Object... args); static String join(String split, Function<T, String> function, Collection<T> args); static String join(String split, Function<T, String> function, T ... args); static boolean isEmpty(String str); static String[] splitRemoveEmpty(String regex, String str); static boolean trimEquals(String str1, String str2, boolean ignoreCase); static boolean trimEquals(String str1, String str2); static String[] splitByLen(String buff, int splitLen); static int compareVersion(String version1, String version2); static String[] splitByLineRemoveEmpty(String str);  }
@Test public void testSubHead(){ Assert.assertEquals("12345", StringUtil.subHead("12345", 5)); Assert.assertEquals("12345", StringUtil.subHead("123456", 5)); }