public static String getAbbreviateClassName(String className) { List<String> srcList = Arrays.asList(className.split("\.")); List<String> dstList = new LinkedList<>(); srcList.stream().limit(srcList.size() - 1L).forEach(item -> dstList.add(item.substring(0, 1))); dstList.add(srcList.get(srcList.size() - 1)); return String.join(".", dstList); } public static void main(String[] args) { String a = "com.test.TestLog"; System.out.println(getAbbreviateClassName(a)); }
c.t.TestLog