1.StringUtilsä¸ isNotEmpty åisNotBlankçåºå«
StringUtilsä¸ isNotEmpty åisNotBlankçåºå«
Ã
loading..
èµè®¯ | å®å ¨ | 论å | ä¸è½½ | 读书 | ç¨åºå¼å | æ°æ®åº | ç³»ç» | ç½ç» | çµå书 | ç«é¿å¦é¢ | æºç | QQ | ä¸æ | èè¯ | æå |
软件å¼å| webå端| Webå¼å| 移å¨å¼å| 综åç¼ç¨|
é¦é¡µ > ç¨åºå¼å > 软件å¼å > Java > æ£æ
StringUtilsä¸ isNotEmpty åisNotBlankçåºå«
-- :: ææ¥è¯´ä¸¤å¥ ä½è ï¼sandeziVIP
æ¶è æè¦æ稿
StringUtilsæ¹æ³çæä½å¯¹è±¡æ¯java.lang.Stringç±»åç对象ï¼æ¯JDKæä¾çStringç±»åæä½æ¹æ³çè¡¥å ï¼å¹¶ä¸æ¯nullå®å ¨ç(å³å¦æè¾å ¥åæ°String为nullåä¸ä¼æåºNullPointerExceptionï¼èæ¯åäºç¸åºå¤çï¼ä¾å¦ï¼å¦æè¾å ¥ä¸ºnullåè¿åä¹æ¯nullçï¼å ·ä½å¯ä»¥æ¥çæºä»£ç )ã
é¤äºæé å¨ï¼StringUtilsä¸ä¸å ±æå¤ä¸ªæ¹æ³ï¼å¹¶ä¸é½æ¯staticçï¼æ以æ们å¯ä»¥è¿æ ·è°ç¨StringUtils.xxx()
1. public static boolean isEmpty(String str)
å¤ææå符串æ¯å¦ä¸ºç©ºï¼ä¸ºç©ºçæ åæ¯str==nullæstr.length()==0
ä¸é¢æ¯StringUtilså¤ææ¯å¦ä¸ºç©ºç示ä¾ï¼
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false //注æå¨StringUtilsä¸ç©ºæ ¼ä½é空å¤ç
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
2. public static boolean isNotEmpty(String str)
å¤ææå符串æ¯å¦é空ï¼çäº!isEmpty(String str)
ä¸é¢æ¯ç¤ºä¾ï¼
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
3. public static boolean isBlank(String str)
å¤ææå符串æ¯å¦ä¸ºç©ºæé¿åº¦ä¸º0æç±ç©ºç½ç¬¦(whitespace)ææ
ä¸é¢æ¯ç¤ºä¾ï¼
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("\t \n \f \r") = true //对äºå¶è¡¨ç¬¦ãæ¢è¡ç¬¦ãæ¢é¡µç¬¦åå车符StringUtils.isBlank()åè¯ä¸ºç©ºç½ç¬¦
StringUtils.isBlank("\b") = false //"\b"为åè¯è¾¹ç符
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
4. public static boolean isNotBlank(String str)
å¤ææå符串æ¯å¦ä¸ä¸ºç©ºä¸é¿åº¦ä¸ä¸º0ä¸ä¸ç±ç©ºç½ç¬¦(whitespace)ææï¼çäº!isBlank(String str)
ä¸é¢æ¯ç¤ºä¾ï¼
StringUtils.isNotBlank(null) = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("\t \n \f \r") = false
StringUtils.isNotBlank("\b") = true
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true
å ¶ä»æ¹æ³ä»ç»ï¼
5. public static String trim(String str)
å»æå符串两端çæ§å¶ç¬¦(control characters,源码cf按键精灵自瞄源码 char <= ),å¦æè¾å ¥ä¸ºnullåè¿ånull
ä¸é¢æ¯ç¤ºä¾ï¼
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim(" \b \t \n \f \r ") = ""
StringUtils.trim(" \n\tss \b") = "ss"
StringUtils.trim(" d d dd ") = "d d dd"
StringUtils.trim("dd ") = "dd"
StringUtils.trim(" dd ") = "dd"
6. public static String trimToNull(String str)
å»æå符串两端çæ§å¶ç¬¦(control characters, char <= ),å¦æå为nullæ""ï¼åè¿ånull
ä¸é¢æ¯ç¤ºä¾ï¼
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" ") = null
StringUtils.trimToNull(" \b \t \n \f \r ") = null
StringUtils.trimToNull(" \n\tss \b") = "ss"
StringUtils.trimToNull(" d d dd ") = "d d dd"
StringUtils.trimToNull("dd ") = "dd"
StringUtils.trimToNull(" dd ") = "dd"
7. public static String trimToEmpty(String str)
å»æå符串两端çæ§å¶ç¬¦(control characters, char <= ),å¦æå为nullæ""ï¼åè¿å""
ä¸é¢æ¯ç¤ºä¾ï¼
StringUtils.trimToEmpty(null) = ""
StringUtils.trimToEmpty("") = ""
StringUtils.trimToEmpty(" ") = ""
StringUtils.trimToEmpty(" \b \t \n \f \r ") = ""
StringUtils.trimToEmpty(" \n\tss \b") = "ss"
StringUtils.trimToEmpty(" d d dd ") = "d d dd"
StringUtils.trimToEmpty("dd ") = "dd"
StringUtils.trimToEmpty(" dd ") = "dd"
8. public static String strip(String str)
å»æå符串两端ç空ç½ç¬¦(whitespace)ï¼å¦æè¾å ¥ä¸ºnullåè¿ånull
ä¸é¢æ¯ç¤ºä¾(注æåtrim()çåºå«)ï¼
StringUtils.strip(null) = null
StringUtils.strip("") = ""
StringUtils.strip(" ") = ""
StringUtils.strip(" \b \t \n \f \r ") = "\b"
StringUtils.strip(" \n\tss \b") = "ss \b"
StringUtils.strip(" d d dd ") = "d d dd"
StringUtils.strip("dd ") = "dd"
StringUtils.strip(" dd ") = "dd"
9. public static String stripToNull(String str)
å»æå符串两端ç空ç½ç¬¦(whitespace)ï¼å¦æå为nullæ""ï¼åè¿ånull
ä¸é¢æ¯ç¤ºä¾(注æåtrimToNull()çåºå«)ï¼
StringUtils.stripToNull(null) = null
StringUtils.stripToNull("") = null
StringUtils.stripToNull(" ") = null
StringUtils.stripToNull(" \b \t \n \f \r ") = "\b"
StringUtils.stripToNull(" \n\tss \b") = "ss \b"
StringUtils.stripToNull(" d d dd ") = "d d dd"
StringUtils.stripToNull("dd ") = "dd"
StringUtils.stripToNull(" dd ") = "dd"
. public static String stripToEmpty(String str)
å»æå符串两端ç空ç½ç¬¦(whitespace)ï¼å¦æå为nullæ""ï¼åè¿å""
ä¸é¢æ¯ç¤ºä¾(注æåtrimToEmpty()çåºå«)ï¼
StringUtils.stripToNull(null) = ""
StringUtils.stripToNull("") = ""
StringUtils.stripToNull(" ") = ""
StringUtils.stripToNull(" \b \t \n \f \r ") = "\b"
StringUtils.stripToNull(" \n\tss \b") = "ss \b"
StringUtils.stripToNull(" d d dd ") = "d d dd"
StringUtils.stripToNull("dd ") = "dd"
StringUtils.stripToNull(" dd ") = "dd"