zoukankan      html  css  js  c++  java
  • org.apache.commons.lang3.StringUtils的用法

    早在两个月前了解到了org.apache.commons.lang3.StringUtils的用法,但是现在还是每次使用每次都忘记每个方法的具体用法,赶紧整理下来:

    例子说明:

         String a = "123sdffff,,dddd,";
            String[] b = StringUtils.split(a, ",");
            System.out.println(Arrays.toString(b) + "-----------split");
            String[] c = StringUtils.splitByWholeSeparator(a, ",");
            System.out.println(Arrays.toString(c)+ "-----------splitByWholeSeparator");
            String[] g = StringUtils.splitByWholeSeparatorPreserveAllTokens(a, ",");
            System.out.println(Arrays.toString(g)+ "-----------splitByWholeSeparatorPreserveAllTokens");
            String[] d = StringUtils.splitPreserveAllTokens(a, ",");
            System.out.println(Arrays.toString(d)+ "-----------splitPreserveAllTokens");
            String[] e = StringUtils.splitByCharacterType(a);
            System.out.println(Arrays.toString(e)+ "-----------splitByCharacterType");
            String[] f = StringUtils.splitByCharacterTypeCamelCase(a);
            System.out.println(Arrays.toString(f)+ "-----------splitByCharacterTypeCamelCase");
            String[] h = StringUtils.splitPreserveAllTokens(a);
            System.out.println(Arrays.toString(h)+ "-----------splitPreserveAllTokens(a)");

    运行结果:

    [123sdffff, dddd]-----------split
    [123sdffff, dddd, ]-----------splitByWholeSeparator
    [123sdffff, , dddd, ]-----------splitByWholeSeparatorPreserveAllTokens
    [123sdffff, , dddd, ]-----------splitPreserveAllTokens
    [123, sdffff, ,,, dddd, ,]-----------splitByCharacterType
    [123, sdffff, ,,, dddd, ,]-----------splitByCharacterTypeCamelCase
    [123sdffff,,dddd,]-----------splitPreserveAllTokens(a)

    结果显示:

    split()方法: 分割字符串过程中会自动忽略所有的空项;

    splitByWholeSeparator方法:分割字符串过程中会忽略中间的空项,保留末尾的空项;

    splitByWholeSeparatorPreserveAllToKens方法及splitPreserveAllToKens方法作用相同:分割字符串过程中会按照每个分隔符进行分割,不忽略任何空白项;

    splitByCharacterType方法及splitByCharacterTypeCamelCase方法:按照字符类型进行分割。

     
  • 相关阅读:
    python locust 性能测试:locust安装和一些参数介绍
    输入一串字符,检查是否可以组成friend
    Django基础
    JQuery基础
    Javascript基础
    CSS基础
    HTML基础
    MYSQL数据库
    I/O模型
    协程-----Coroutine
  • 原文地址:https://www.cnblogs.com/daisyleamo/p/3360563.html
Copyright © 2011-2022 走看看