zoukankan      html  css  js  c++  java
  • org.apache.commons等常用工具学习

    StringUtils

    1,StringUtils.isNotBlank

    isNotEmpty :

    判断某字符串是否非空

    StringUtils.isNotEmpty(null) = false

    StringUtils.isNotEmpty("") = false

    StringUtils.isNotEmpty(" ") = true

    StringUtils.isNotEmpty("bob") = true isNotBlank:

    判断某字符串是否不为空且长度不为0且不由空白符(whitespace)构成,

    下面是示例:

    StringUtils.isNotBlank(null) = false

    StringUtils.isNotBlank("") = false

    StringUtils.isNotBlank(" ") = false

    StringUtils.isNotBlank(" f ") = false

    beanUtils

    beanUtils 对象转map,

    https://www.cnblogs.com/jing1617/p/7007580.html

    <dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.9.3</version>
    </dependency>

    直接转,没有的字段是默认值,要自己处理,注意要先new出来,在apache-commons下需要时public

    SerializationUtils.clone(obj)

    Student student3 = SerializationUtils.clone(Student);

    例外几种方法的深拷贝:1,set,2,json,3,dozer(没有看

    ClassUtils

    System.out.println(genHeader("ClassUtilsDemo"));
    System.out.println("获取类实现的所有接口.");
    System.out.println(ClassUtils.getAllInterfaces(Date.class));

    System.out.println("获取类所有父类.");
    System.out.println(ClassUtils.getAllSuperclasses(Date.class));

    System.out.println("获取简单类名.");
    System.out.println(ClassUtils.getShortClassName(Date.class));

    System.out.println("获取包名.");
    System.out.println(ClassUtils.getPackageName(Date.class));

    System.out.println("判断是否可以转型.");
    System.out.println(ClassUtils.isAssignable(Date.class, Object.class));
    System.out.println(ClassUtils.isAssignable(Object.class, Date.class));

    获取类实现的所有接口.
    [interface java.io.Serializable, interface java.lang.Cloneable, interface java.lang.Comparable]
    获取类所有父类.
    [class java.lang.Object]
    获取简单类名.
    Date
    获取包名.
    java.util
    判断是否可以转型.
    true
    false

    WordUtils

    private void wordUtilsDemo() {
    System.out.println("单词处理功能");
    String str1 = "wOrD";
    String str2 = "ghj ui po";
    System.out.println(WordUtils.capitalize(str1)); // 首字母大写
    System.out.println(WordUtils.capitalizeFully(str1)); // 首字母大写其它字母小写
    char[] ctrg = {'.'};
    System.out.println(WordUtils.capitalizeFully("i aM.fine", ctrg)); // 在规则地方转换
    System.out.println(WordUtils.initials(str1)); // 获取首字母
    System.out.println(WordUtils.initials("Ben John Lee", null)); // 取每个单词的首字母
    char[] ctr = {' ', '.'};
    System.out.println(WordUtils.initials("Ben J.Lee", ctr)); // 按指定规则获取首字母
    System.out.println(WordUtils.swapCase(str1)); // 大小写逆转
    System.out.println(WordUtils.wrap(str2, 1)); // 解析 和 等字符}

    单词处理功能
    WOrD
    Word
    I am.Fine
    w
    BJL
    BJL
    WoRd
    ghj
    ui po

    CollectionUtils

    CollectionUtils.isNotEmpty(apply4CDtoList);
    CollectionUtils.isEmpty(apply4CDtoList);

  • 相关阅读:
    在eclipse中API的封装和调用
    冒泡排序
    java中阻止类的继承
    java中数组复制的两种方式
    ssh框架搭建出现的异常: class com.my.entity.user not found while looking for property: id
    ssh框架中struts.xml 的配置参数详解
    线程的五种状态
    Sql Server 分页
    window.opener 子窗体操作父窗体
    贪心算法--汽车加油问题
  • 原文地址:https://www.cnblogs.com/vhyc/p/10666116.html
Copyright © 2011-2022 走看看