`
ctf_htj
  • 浏览: 3795 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Apache commons Utils包学习

阅读更多

Apache commons Utils包学习

 

 

RandomStringUtils :生成随机的字符串

       /**

        * 生成由数字组成的随机串

        */

       String s = RandomStringUtils.randomNumeric(10);

        System.out.println(RandomStringUtils.randomNumeric(10));//7337081788

      

       /**

        * 用指定的字符生成随机串

        */

       String ss = RandomStringUtils.random(10, new char[]{'a', 'b', 'c'});

       System.out.println(ss);//cacaccbbaa

 

       /**

        * 用指定的字符串中的字符随机生成字符串

        */

       String sss = RandomStringUtils.random(10, "thunisoft");

       System.out.println(sss);//tffnhftsut

 

ClassUtils:用于对Java类的操作,不使用反射

       /**

        * convertClassNamesToClasses

        */

       List<String> lst = new ArrayList<String>();

       lst.add("com.ying.lang.booleanutils.BooleanUtilsTest");

       List<Class> lst_clas = ClassUtils.convertClassNamesToClasses(lst);

       System.out.println(lst_clas);

      

       /**

        * convertClassesToClassNames

        */

       Class[] clas_s = new Class[] {ClassUtilsTest.class};

       List<Class> lst1 = Arrays.asList(clas_s);

        System.out.println(ClassUtils.convertClassesToClassNames(lst1));

      

       /**

        * getAllInterfaces

        */

        System.out.println(ClassUtils.getAllInterfaces(ArrayList.class));

      

       /**

        * getAllSuperclasses

        */

        System.out.println(ClassUtils.getAllSuperclasses(ArrayList.class));

 

 

ArrayUtils

       String[] str = new String[]{"a", "b", "c", "d", "e", "f"};

       /**

        * 增加

        */

       str = (String[]) ArrayUtils.add(str, "g");

      

       /**

        * 查找

        */

       int index = ArrayUtils.indexOf(str, "b");

       System.out.println(index);

      

       /**

        * 删除

        */

//     str  = (String[]) ArrayUtils.remove(str, 3);

      

       /**

        * 子数组

        */

//     str = (String[]) ArrayUtils.subarray(str, 1, 2);

      

       /**

        * 逆序

        */

       ArrayUtils.reverse(str);

       System.out.println(Arrays.asList(str));

       System.out.println(StringUtils.join(str, ","));

 

 

StringUtils : 很常用的一个类,对字符串的处理类。

    //判断空

       System.out.println(StringUtils.isEmpty(null)); // true

       System.out.println(StringUtils.isEmpty("")); // true

       System.out.println(StringUtils.isEmpty(" ")); // false

       System.out.println(StringUtils.isEmpty("abc")); // false

       //判断是否空白

       System.out.println(StringUtils.isBlank(null)); // true

       System.out.println(StringUtils.isBlank("")); // true

       System.out.println(StringUtils.isBlank(" ")); // true

       System.out.println(StringUtils.isBlank("abc")); // false

      

       //去除首尾空白

       System.out.println(StringUtils.trim("  abc  "));// abc

       System.out.println(StringUtils.strip(" abc")); // abc

       System.out.println(StringUtils.strip("abc  ")); // abc

       System.out.println(StringUtils.strip(" abc  ")); // abc

       System.out.println(StringUtils.strip(" a bc  ")); // a bc

       String target = "    abc";

       System.out.println(IsEmptyTest.test(target));

      

       /**

        * 是否空白字符

        */

       System.out.println(StringUtils.isWhitespace("")); // true

       System.out.println(StringUtils.isWhitespace(" ")); // true

      

       /**

        * 简略

        */

       System.out.println(StringUtils.abbreviate("thunisoft", 7)); // thun...

       System.out.println(StringUtils.abbreviate("thunisoft", 5)); // th...

       String str = "thunisoft";

       /**

        * 首字母大写

        */

       System.out.println(StringUtils.capitalize("thunisoft")); // Thunisoft

      

       //左侧填充

       System.out.println(StringUtils.leftPad("123", 6, "0"));// 000123

       //右侧填充

       System.out.println(StringUtils.rightPad("123", 6, "0"));// 123000

      

       System.out.println(StringUtils.center("thunisoft", 15)); //   thunisoft(左侧填充空白)

      

       System.out.println(StringUtils.center("thunisoft", 15, "-")); // ---thunisoft---- (左右填充)

      

       /**

        * 去除换行

        */

       System.out.println("\r" + "thunisoft" + "\r");

       System.out.println(StringUtils.chomp("\r" + "thunisoft" + "\r"));

       /**

        * 删掉最后一个字符

        */

       System.out.println(StringUtils.chop("thunisoft")); // thunisof

      

       /**

        * 找出两个字符不一样的位置

        */

       System.out.println(StringUtils.indexOfDifference("thunisoft", "thunisofff")); // 8

       System.out.println(StringUtils.difference("thunisoft", "thunisofff")); // ff

      

       /**

        * remove

        */

       System.out.println(StringUtils.remove("thunisoft", "t"));   // hunisof

      

       /**

        * 重复一个字符串n

        */

       System.out.println(StringUtils.repeat("thunisoft", 3)); // thunisoftthunisoftthunisoft

 

分享到:
评论

相关推荐

    org.apache.commons.lang jar包下载(commons-lang3-3.1.jar)

    org.apache.commons.lang.ClassUtils.class org.apache.commons.lang.Entities$ArrayEntityMap.class org.apache.commons.lang.Entities$BinaryEntityMap.class org.apache.commons.lang.Entities$EntityMap....

    org.apache.commons相关的所以jar包

    org.apache.commons相关的所以jar包,包括commons-beanutils-1.8.0-bin.zip;commons-betwixt-0.8.zip;commons-cli-1.1.zip;commons-codec-1.3.zip;commons-collections-3.2.1-bin.zip;commons-digester-1.8.zip...

    Apache Commons Compress

    Apache Commons Compress ( commons-compress-1.13-bin.zip)

    Java字符串加密使用的一个jar包 commons-lang3-3.1.jar下载

    Java字符串加密使用到的一个jar包 commons-lang3-3.1...org.apache.commons.lang3.ClassUtils.class org.apache.commons.lang3.Validate.class org.apache.commons.lang3.SystemUtils.class 。。。。。。。。。。。。。

    commons-lang.jar

    org.apache.commons.lang.ClassUtils.class org.apache.commons.lang.Entities$ArrayEntityMap.class org.apache.commons.lang.Entities$BinaryEntityMap.class org.apache.commons.lang.Entities$EntityMap.class ...

    Commons-dbutils1.7 jar包.rar

    commons-dbutils包是Apache开源组织提供的用于操作数据库的工具包。简单来讲,这个工具包就是用来更加方便我们操作数据库的,最近工作中使用了一下,感觉确实方便很多,基本告别自己封装JDBC代码对数据库进行增删改...

    commons.lang3.ClassUtils 源码中文注释

    org.apache.commons.lang3.ClassUtils 源码中文注释,之后会加上其他的工具类注释,方便以后复习阅读

    commons-lang3-3.1 API

    这一组API的所有包名都以org.apache.commons.lang开头,共有如下8个包: org.apache.commons.lang org.apache.commons.lang.builder org.apache.commons.lang.enum org.apache.commons.lang.enums org.apache....

    commons-collections-3.2.2.jar

    apache-common系列中的重要的成员:apache-common-collections。包中对Java中的集合类进行了一定的补充,定义了一些全新的集合,当然也是实现了Collection接口的,比如Bag,BidiMap。同时拥有新版本的原有集合,比如...

    commons-beanutils-1.9.CHM

    commons-beanutils.chm帮助文档 commons-beanutil开源库是apache组织的一个基础的开源库。为apache中很多类提供工具方法。学习它是学习其它开源库实现的基础。...本文研究的是v1.7版本号的commons-utils类库。

    base64 三个jar包

    使用base64加解密的jar包,提供三种,对应就有三种方法。详细操作博客里有,不会的小伙伴可以自己去查看!啊啊啊啊,还不够100字。

    commons-lang3-8.1.jar官方工具包

    java 开发工具commons-lang3-8.1 jar包,有org.apache.commons.lang3.StringUtils; org.apache.commons.lang3.reflect.FieldUtils;等类

    commons-beanutils-1.8.3.jar commons-codec-1.7.jar commons-collections-3.2.1.jar

    commons各种jar包下载 commons-beanutils-1.8.3.jar commons-codec-1.7.jar commons-collections-3.2.1.jar commons-dbcp-1.4.jar commons-digester-2.1.jar commons-jexl-2.1.1.jar commons-lang-2.6.jar commons-...

    goutils:GoUtils是Apache Commons的一些字符串操作库的Go实现。 这是一个开源项目,旨在为Go用户提供实用程序功能,以各种方式操作字符串

    它是Java Apache Commons的某些字符串操作库的Go实现。 GoUtils包括以下Java Apache Commons类: WordUtils RandomStringUtils StringUtils(部分实现)安装如果您在系统上设置了Go,请从命令行/终端内的GOPATH目录...

    IOUtils(commons-io-1.4.jar、commons-fileupload-1.2.1.jar等等)

    org.apache.commons的所有jar包:commons-io-1.4.jar、commons-fileupload-1.2.1.jar等等

    自定封装StringUtils常用方法

    继承了org.apache.commons.lang3.StringUtils工具类,加入了部分常用方法,使用时直接添加到项目的公共utils下,同时在pom.xml加入依赖: &lt;!-- ...

    commons-codec-1.14.jar

    import org.apache.commons.codec.binary.Base64; /* * AES加解密算法 * * @author jueyue * 加密用的Key 可以用26个字母和数字组成,最好不要用保留字符,虽然不会错,至于怎么裁决,个人看情况而定 ...

    commons-io-2.4-docs

    io utils 是apache 提供的方便数据操作的jar包,此文档有助于快速入门

    mongo-utils:一个小的Java MongoDB帮助程序库,可以更轻松地设置和访问集合以及转换实体

    org.apache.commons:commons-lang3:3.4 com.google.collections:google-collections:1.0 添加到您的项目 该库可从 只需添加 compile 'io.seventyone:mongo-utils:0.0.2' 对你的依赖。 该代码已记录在案,随后将...

    coffee-commons

    这个包类似utils,主要是最简单的utils方法的集合,我不建议自己实现utils类,毕竟apache-commons和guava都已经帮我们实现了很多,主要是脚手架内部需要使用的方法封装,如类扫描等 这里面重点关注...

Global site tag (gtag.js) - Google Analytics