public static String trim(final String str, final char ch) {
        if (isEmpty(str)) {
            return null;
        }

        final char[] chars = str.toCharArray();

        int i = 0, j = chars.length - 1;
        // noinspection StatementWithEmptyBody
        for (; i < chars.length && chars[i] == ch; i++) {
        }
        // noinspection StatementWithEmptyBody
        for (; j > 0 && chars[j] == ch; j--) {
        }

        return new String(chars, i, j - i + 1);
    }
@Test
    public void testTrim() {
        assertEquals(StringUtil.trim("aaabcdefaaa", 'a'), "bcdef");
        assertEquals(StringUtil.trim("bcdef", 'a'), "bcdef");
        assertEquals(StringUtil.trim("abcdef", 'a'), "bcdef");
        assertEquals(StringUtil.trim("abcdef", 'f'), "abcde");
    }