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



     



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

       
  • 相关阅读:
    mmsplayer V2 for android 抢先发布
    mmsplayer v2 windows C 之(mmsplayer_wave )
    mmsplayer v2 java 之(MmsplayerActivity Activity类)
    mmsplayer V2 for windows 发布
    今天休息,明天晚上继续IOS版本mmsplayer V2
    mmsplayer v2 java 之(MmsplayerActivity Activity类)
    mmsplayer V2 for windows 发布
    自定义函数:删除数组B中与数组A重复的值
    LotusScript方法扩展
    MS SQL 2005 SP2新功能
  • 原文地址:https://www.cnblogs.com/hqlong/p/6430090.html
Copyright © 2011-2022 走看看