StringUtils常用方法集合

public class test {
​
    /**
     * unqualify:获取最后一个.之后的字符串
     */
    @Test
    public void test31() {
        String s = StringUtils.unqualify("w.s.y");
        System.out.println(s);
        /** 重载-参数不同-选择指定的分隔符获取最后的字符串 */
        String ss = StringUtils.unqualify("w-s-y",'-');
        System.out.println(ss);
    }
​
    /**
     * uncapitalize:将字符的第一个字母改为小写
     */
    @Test
    public void test30() {
        String s = StringUtils.uncapitalize("Wsy");
        System.out.println(s);
    }
​
    /**
     * trimAllWhitespace:去掉字符串中的所有空格
     */
    @Test
    public void test23() {
        String string = StringUtils.trimAllWhitespace("w s y");
        System.out.println(string);
​
    }
​
    /**
     * trimWhitespace:删除字符串前边和后边的空格
     */
    @Test
    public void test29() {
        String s = StringUtils.trimWhitespace(" w s y ");
        System.out.println(s);
    }
​
    /**
     * trimTrailingWhitespace:删除字符串后边的空格
     */
    @Test
    public void test28() {
        String string = StringUtils.trimTrailingWhitespace("wsy   ");
        System.out.println(string);
    }
​
    /**
     * trimLeadingWhitespace:删除字符串前边的空格
     */
    @Test
    public void test27() {
        String s = StringUtils.trimLeadingWhitespace(" wsy");
        System.out.println(s);
    }
​
    /**
     * trimTrailingCharacter:删除字符串的最后一个字符,第一个参数是字符串,第二个参数是要删除的字符,只能是字符串的首字符
     */
    @Test
    public void test26() {
        String s = StringUtils.trimTrailingCharacter("wsy", 'y');
        System.out.println(s);
    }
​
    /**
     * trimLeadingCharacter:删除字符串的第一个字符,第一个参数是字符串,第二个参数是要删除的字符,只能是字符串的首字符
     */
    @Test
    public void test25() {
        String s = StringUtils.trimLeadingCharacter("wsy", 'w');
        System.out.println(s);
    }
​
    /**
     * trimArrayElements:删除每个数组的头部和尾部的空格
     */
    @Test
    public void test24() {
        String[] students ={"1","5","     879","4"};
        String[] strings = StringUtils.trimArrayElements(students);
        for (String s : strings) {
            System.out.println(s);
        }
    }
​
    /**
     * splitArrayElementsIntoProperties:按照指定字符将数组转为对象,指定的字符必须是数组中的字符串中有的,转为对象会换为等于号
     */
    @Test
    public void test22() {
        String[] lang =new String[]{"key:value","name:三郎"};
        Properties properties = StringUtils.splitArrayElementsIntoProperties(lang, ":");
        System.out.println(properties);
​
        /** 重载--参数不同--新增删除任何参数 */
        Properties properties1 = StringUtils.splitArrayElementsIntoProperties(lang, ":", "三");
        System.out.println(properties1);
    }
​
    /**
     * sortStringArray:对数组进行排序。
     */
    @Test
    public void test21() {
        String[] num ={"1","5","2","4"};
        String[] strings = StringUtils.sortStringArray(num);
        for (String s : strings) {
            System.out.println(s);
        }
    }
​
    /**
     * removeDuplicateStrings:移除数组中的重复字符串。
     */
    @Test
    public void test20() {
        String[] stringList ={"wsy", "wkh", "zdx", "wll", "wsy"};
        String[] strings = StringUtils.removeDuplicateStrings(stringList);
        for (String s : strings) {
            System.out.println(s);
        }
    }
​
    /**
     * matchesCharacter:测试特定的字符和规定的字符是否匹配,char是单字符,单引号。
     */
    @Test
    public void test19() {
        boolean b = StringUtils.matchesCharacter("wsy", 'w');
        System.out.println(b);
    }
​
    /**
     * hasLength:检查给定CharSequence/String的既不是null,长度也不是0。
     */
    @Test
    public void test18() {
        boolean s = StringUtils.hasLength("wsy");
        System.out.println(s);
    }
​
    /**
     * endsWithIgnoreCase:测试是否以指定的字符结尾,忽略大写/小写。
     */
    @Test
    public void test17() {
        boolean b = StringUtils.endsWithIgnoreCase("wsy", "w");
        System.out.println(b);
    }
​
    /**
     * delimitedListToStringArray:计算某个字符在字符串中出现的次数。
     */
    @Test
    public void test16() {
        String[] array = StringUtils.delimitedListToStringArray("wsy*wll", "*");
        for (String s : array) {
            System.out.println(s);
        }
        /** 重载--参数不同--新增删除任何参数 */
        String[] arrays = StringUtils.delimitedListToStringArray("wsy*wll", "*","yw");
        for (String s : arrays) {
            System.out.println(s);
        }
    }
​
​
    /**
     * countOccurrencesOf:计算某个字符在字符串中出现的次数。
     */
    @Test
    public void test14() {
        int i = StringUtils.countOccurrencesOf("wkgzdxwllwsy", "w");
        System.out.println(i);
    }
​
    /**
     * containsWhitespace:检查字符串是否含任何空白字符。
     */
    @Test
    public void test13() {
        boolean s = StringUtils.containsWhitespace("wsy ");
        System.out.println(s);
​
    }
​
    /**
     * concatenateStringArrays:将给定的String数组连接成一个,包含重复的元素。
     */
    @Test
    public void test12() {
        String[] bro ={"wsy","wll"};
        String[] family ={"wkh","zdx","wsy","wll"};
        String[] strings = StringUtils.concatenateStringArrays(bro, family);
        for (String s : strings) {
            System.out.println(s);
        }
    }
​
    /**
     * commaDelimitedListToStringArray:将逗号分隔的字符转换为字符串数组
     */
    @Test
    public void test11() {
        String[] strings = StringUtils.commaDelimitedListToStringArray("wsy,wll");
        for (String s : strings) {
            System.out.println(s);
        }
    }
​
    /**
     * commaDelimitedListToSet:将逗号分隔的字符串转为set集合
     */
    @Test
    public void test10() {
        Set<String> strings = StringUtils.commaDelimitedListToSet("wsy,wll");
        for (String s : strings) {
            System.out.println(s);
        }
    }
​
    /**
     * collectionToDelimitedString:按照指定的字符将集合分割为字符串
     */
    @Test
    public void test9() {
        List<String> stringList = Arrays.asList("wsy", "wll", "zdx", "wkh");
        String s = StringUtils.collectionToDelimitedString(stringList, "$");
        System.out.println(s);
    }
​
    /**
     * collectionToCommaDelimitedString:将list集合转为逗号分割的字符串
     */
    @Test
    public void test8() {
        List<String> stringList = Arrays.asList("wsy", "wll", "zdx", "wkh");
        String s = StringUtils.collectionToCommaDelimitedString(stringList);
        System.out.println(s);
    }
​
    /**
     * capitalize:将字符串第一个字母转为大写
     */
    @Test
    public void test7() {
        String san = StringUtils.capitalize("san");
        System.out.println(san);
    }
​
    /**
     * arrayToDelimitedString:将String数组转换为指定分隔符分隔的字符串
     */
    @Test
    public void test6() {
        String[] model = {"用户","美食"};
        String s = StringUtils.arrayToDelimitedString(model,"&&");
        System.out.println(s);
    }
​
    /**
     * arrayToCommaDelimitedString:将String数组转换为逗号分隔的字符串
     */
    @Test
    public void test5() {
        String[] sex ={"男人","女人"};
        String s = StringUtils.arrayToCommaDelimitedString(sex);
        System.out.println(s);
    }
​
    /**
     * split:通过逗号把字符串分割成一个数组
     */
    @Test
    public void test4() {
        String[] split = StringUtils.split("wyy,wll", ",");
        for (String s : split) {
            System.out.println(s);
        }
    }
​
    /**
     * replace:把字符串中所有的张三替换为三郎
     */
    @Test
    public void test3() {
        String replace = StringUtils.replace("张三李四王五张三", "张三", "三郎");
        System.out.println(replace);
    }
​
    /**
     * delete:删除字符串中指定的字符串
     */
    @Test
    public void test2() {
        String str = StringUtils.delete("wsy", "少");
        System.out.println(str);
    }
​
    /**
     * deleteAny:删除任何,删除所有的w和t。
     */
    @Test
    public void test15() {
        String s = StringUtils.deleteAny("wkgzdxwllwsy", "w");
        System.out.println(s);
    }
​
    /**
     * addStringToArray:追加特定的字符串给特定的String数组,返回一个新的数组
     */
    @Test
    public void test1() {
        String[] name = {"张三"};
        String[] addStringToArray = StringUtils.addStringToArray(name,"lisi");
        for (String s : addStringToArray) {
            System.out.println(s);
        }
    }
}