zoukankan      html  css  js  c++  java
  • 实用的 集合工具类 和 String工具类

    集合工具类:CollectionUtil
    method:

    1.isNotEmpty() 不为空

    2.isEmpty() 为空

    举例:map集合

            Map<String,String> mapA= new HashMap<>();
            Map<String,String> mapB= new HashMap<>();
            Map<String,String> mapC= new HashMap<>();
            mapA.put("1", "1");
            mapB.put(null, null);
            System.out.println(CollectionUtil.isNotEmpty(mapA));//true
            System.out.println(CollectionUtil.isNotEmpty(mapB));//true
            System.out.println(CollectionUtil.isNotEmpty(mapC));//false

    String工具类:StringUtil

    method:
    1.isNotBlank
    2.isBlank
            String sA= null;
            String sB= "";
            String sC= "123";
            System.out.println(StringUtil.isNotBlank(sB));//false
            System.out.println(StringUtil.isNotBlank(sA));//false
            System.out.println(StringUtil.isNotBlank(sC));//true

    3.alignRight("str", *)  扩展并右对齐字符串,用空格' '填充左边(*为数字类型,可以为负数,表示消除空格数量)

    4.alignLeft("str", *)  扩展并右对齐字符串,用空格' '填充左边 (*为数字类型,可以为负数,表示消除空格数量)

    5.center("str",*)   用空格' '填充两边。

    6.capitalize("str")   将字符串的首字符转成大写(Character.toTitleCase),其它字符不变。

    7.chomp("str","separator")   删除字符串末尾的指定字符串。如果字符串不以该字符串结尾,则什么也不做。

    8.containsOnly("str","valid")   检查字符串是是否只包含指定字符集合中的字符。但是空字符串永远返回true.

    9.containsNone("str", "valid")   检查字符串是是否不包含指定字符集合中的字符。 但是空字符串永远返回true.

    10.equals(): 比较两个字符串是否相等,如果两个均为null,则也认为相等

     
      StringUtils.equals("", "");   //true
     
      StringUtils.equals(null, null);  //true
     
      StringUtils.equals(null, "");  //false
     
      StringUtils.equals("",null);  //false
     
      StringUtils.equals(null,"");  //false
     
      StringUtils.equalsIgnoreCase("ss", "Ss");  //不区分大小写--true



     



     还有一些不,不一一贴上来了

       
  • 相关阅读:
    项目中使用Redis的游标scan的一些小问题
    mac上使用Sequel Pro工具SSH连接数据库
    virtualbox通过Nat模式上网,宿主机与宿主机互通
    Mac系统docker初探
    QQ互联,填写回调时注意事项
    Centos中编辑php扩展库
    samba服务介绍
    bash常用功能
    vsftp服务介绍与相关实验
    shell概述与echo命令
  • 原文地址:https://www.cnblogs.com/hqlong/p/6430090.html
Copyright © 2011-2022 走看看