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



     



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

       
  • 相关阅读:
    硬盘安装windows2008的方法
    win7,win2008R2的vs2008 破解方法
    学习正则表达式
    C#里内置的DateTime基本功能
    jQuery Ajax 实例 全解析
    TreeView 部署后不能显示图标、js出错原因
    js 操作Listbox js 获取Listbox选择的值的代码
    ajax调用后台Datatable
    转:jquery刷新页面 页面跳转 js常用函数
    GridView多行表头的实现
  • 原文地址:https://www.cnblogs.com/hqlong/p/6430090.html
Copyright © 2011-2022 走看看