当前位置:   article > 正文

SpringBoot 常用工具类----字符串工具类StringUtils_springboot stringutils

springboot stringutils

SpringBoot 常用工具类----字符串工具类StringUtils

1. 简介

字符串工具类StringUtils

2. 工具类

2.1. StringUtils

字符串工具类

       String str="hahahaha";
        /*判断字符串是否为 null,或 ""。注意,包含空白符的字符串为非空
        boolean isEmpty (Object str)*/
       if (StringUtils.isEmpty(str)) {
           log.info("str is null");
       }
       /* 判断字符串是否是以指定内容结束。忽略大小写
        boolean endsWithIgnoreCase (String str, String suffix)*/
        if (StringUtils.endsWithIgnoreCase(str, "aha")) {
           log.info("str is endsWith aha");
       }
       /* 判断字符串是否已指定内容开头。忽略大小写
        boolean startsWithIgnoreCase (String str, String prefix)*/
        if (StringUtils.startsWithIgnoreCase(str, "ha")) {
           log.info("str is startsWith ha");
       }
       /* 是否包含空白符
        boolean containsWhitespace (String str)*/
        if (StringUtils.containsWhitespace(str)) {
           log.info("str is contains whitespace");
       }
        /*判断字符串非空且长度不为 0,即,Not Empty
        boolean hasLength (CharSequence str)*/
        if (StringUtils.hasLength(str)) {
           log.info("str is hasLength");
       }
        /*判断字符串是否包含实际内容,即非仅包含空白符,也就是 Not Blank
        boolean hasText (CharSequence str)*/
        if (StringUtils.hasText(str)) {
           log.info("str is hasText");
       }
        /*判断字符串指定索引处是否包含一个子串。
        boolean substringMatch (CharSequence str,int index, CharSequence substring)*/
        if (StringUtils.substringMatch(str, 0, "ha")) {
           log.info("str is substringMatch");
       }
        /*计算一个字符串中指定子串的出现次数
        int countOccurrencesOf (String str, String sub)*/
        if (StringUtils.countOccurrencesOf(str, "ha") == 2) {
           log.info("str is countOccurrencesOf");
       }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号