亚洲精品中文免费|亚洲日韩中文字幕制服|久久精品亚洲免费|一本之道久久免费

<optgroup id="cczp1"><ruby id="cczp1"><cite id="cczp1"></cite></ruby></optgroup>
  • <acronym id="cczp1"></acronym>
    <acronym id="cczp1"><option id="cczp1"><ol id="cczp1"></ol></option></acronym>
    <delect id="cczp1"></delect>
    <center id="cczp1"></center>
    <delect id="cczp1"></delect><em id="cczp1"><button id="cczp1"><blockquote id="cczp1"></blockquote></button></em>
    1. <optgroup id="cczp1"><td id="cczp1"><dfn id="cczp1"></dfn></td></optgroup>

      isEmpty 和 isBlank 請別亂用了,小心把服務器搞崩

      大家好,我是程序汪,開發(fā)中經(jīng)常有些小細節(jié)容易忽略,這些小細節(jié)往往容易導致代碼缺陷,今天分享一波工具類的小細節(jié)

      也許你兩個都不知道,也許你除了isEmpty/isNotEmpty/isNotBlank/isBlank外,并不知道還有isAnyEmpty/isNoneEmpty/isAnyBlank/isNoneBlank的存在, come on ,讓我們一起來探索org.apache.commons.lang3.StringUtils;這個工具類。

      isEmpty系列

      StringUtils.isEmpty()

      是否為空. 可以看到 ” ” 空格是會繞過這種空格判斷,因為是一個空格,并不是嚴格的空值,會導致 isEmpty(” “)=false

      StringUtils.isEmpty(null) = trueStringUtils.isEmpty(“”) = trueStringUtils.isEmpty(” “) = falseStringUtils.isEmpty(“bob”) = falseStringUtils.isEmpty(” bob “) = false/** * *

      NOTE: This method changed in Lang version 2.0. * It no longer trims the CharSequence. * That functionality is available in isBlank().

      * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is empty or null * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence) */public static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0;}

      StringUtils.isNotEmpty()

      相當于不為空 , = !isEmpty()。

      public static boolean isNotEmpty(final CharSequence cs) { return !isEmpty(cs); }

      StringUtils.isAnyEmpty()

      是否有一個為空,只有一個為空,就為true。

      StringUtils.isAnyEmpty(null) = trueStringUtils.isAnyEmpty(null, “foo”) = trueStringUtils.isAnyEmpty(“”, “bar”) = trueStringUtils.isAnyEmpty(“bob”, “”) = trueStringUtils.isAnyEmpty(” bob “, null) = trueStringUtils.isAnyEmpty(” “, “bar”) = falseStringUtils.isAnyEmpty(“foo”, “bar”) = false/** * @param css the CharSequences to check, may be null or empty * @return {@code true} if any of the CharSequences are empty or null * @since 3.2 */public static boolean isAnyEmpty(final CharSequence… css) { if (ArrayUtils.isEmpty(css)) { return true; } for (final CharSequence cs : css){ if (isEmpty(cs)) { return true; } } return false;}

      StringUtils.isNoneEmpty()

      相當于!isAnyEmpty(css) , 必須所有的值都不為空才返回true

      /** *

      Checks if none of the CharSequences are empty (“”) or null.

      * * * StringUtils.isNoneEmpty(null) = false * StringUtils.isNoneEmpty(null, “foo”) = false * StringUtils.isNoneEmpty(“”, “bar”) = false * StringUtils.isNoneEmpty(“bob”, “”) = false * StringUtils.isNoneEmpty(” bob “, null) = false * StringUtils.isNoneEmpty(” “, “bar”) = true * StringUtils.isNoneEmpty(“foo”, “bar”) = true * * * @param css the CharSequences to check, may be null or empty * @return {@code true} if none of the CharSequences are empty or null * @since 3.2 */public static boolean isNoneEmpty(final CharSequence… css) {

      isBank系列

      StringUtils.isBlank()

      是否為真空值(空格或者空值)

      StringUtils.isBlank(null) = trueStringUtils.isBlank(“”) = trueStringUtils.isBlank(” “) = trueStringUtils.isBlank(“bob”) = falseStringUtils.isBlank(” bob “) = false/** *

      Checks if a CharSequence is whitespace, empty (“”) or null.

      * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is null, empty or whitespace * @since 2.0 * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) */public static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } return true;}

      StringUtils.isNotBlank()

      是否真的不為空,不是空格或者空值 ,相當于!isBlank();

      public static boolean isNotBlank(final CharSequence cs) { return !isBlank(cs); }

      StringUtils.isAnyBlank()

      是否包含任何真空值(包含空格或空值)

      StringUtils.isAnyBlank(null) = trueStringUtils.isAnyBlank(null, “foo”) = trueStringUtils.isAnyBlank(null, null) = trueStringUtils.isAnyBlank(“”, “bar”) = trueStringUtils.isAnyBlank(“bob”, “”) = trueStringUtils.isAnyBlank(” bob “, null) = trueStringUtils.isAnyBlank(” “, “bar”) = trueStringUtils.isAnyBlank(“foo”, “bar”) = false /** *

      Checks if any one of the CharSequences are blank (“”) or null and not whitespace only..

      * @param css the CharSequences to check, may be null or empty * @return {@code true} if any of the CharSequences are blank or null or whitespace only * @since 3.2 */public static boolean isAnyBlank(final CharSequence… css) { if (ArrayUtils.isEmpty(css)) { return true; } for (final CharSequence cs : css){ if (isBlank(cs)) { return true; } } return false;}

      StringUtils.isNoneBlank()

      是否全部都不包含空值或空格

      StringUtils.isNoneBlank(null) = falseStringUtils.isNoneBlank(null, “foo”) = falseStringUtils.isNoneBlank(null, null) = falseStringUtils.isNoneBlank(“”, “bar”) = falseStringUtils.isNoneBlank(“bob”, “”) = falseStringUtils.isNoneBlank(” bob “, null) = falseStringUtils.isNoneBlank(” “, “bar”) = falseStringUtils.isNoneBlank(“foo”, “bar”) = true/** *

      Checks if none of the CharSequences are blank (“”) or null and whitespace only..

      * @param css the CharSequences to check, may be null or empty * @return {@code true} if none of the CharSequences are blank or null or whitespace only * @since 3.2 */public static boolean isNoneBlank(final CharSequence… css) { return !isAnyBlank(css);}

      StringUtils的其他方法

      可以參考官方的文檔,里面有詳細的描述,有些方法還是很好用的。

      https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

      方法名英文解釋中文解釋IsEmpty/IsBlankchecks if a String contains text檢查字符串是否包含文本Trim/Stripremoves leading and trailing whitespace刪除前導和尾隨空格Equals/Comparecompares two strings null-safe比較兩個字符串是否為null安全的startsWithcheck if a String starts with a prefix null-safe檢查字符串是否以前綴null安全開頭endsWithcheck if a String ends with a suffix null-safe檢查字符串是否以后綴null安全結(jié)尾IndexOf/LastIndexOf/Containsnull-safe index-of checks包含空安全索引檢查IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyButindex-of any of a set of Strings任意一組字符串的索引ContainsOnly/ContainsNone/ContainsAnydoes String contains only/none/any of these characters字符串是否僅包含/無/這些字符中的任何一個Substring/Left/Right/Midnull-safe substring extractions字符串安全提取SubstringBefore/SubstringAfter/SubstringBetweensubstring extraction relative to other strings -相對其他字符串的字符串提取Split/Joinsplits a String into an array of substrings and vice versa將字符串拆分為子字符串數(shù)組,反之亦然Remove/Deleteremoves part of a String -刪除字符串的一部分Replace/OverlaySearches a String and replaces one String with another搜索字符串,然后用另一個字符串替換Chomp/Chopremoves the last part of a String刪除字符串的最后一部分AppendIfMissingappends a suffix to the end of the String if not present如果不存在后綴,則在字符串的末尾附加一個后綴PrependIfMissingprepends a prefix to the start of the String if not present如果不存在前綴,則在字符串的開頭添加前綴LeftPad/RightPad/Center/Repeatpads a String填充字符串UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalizechanges the case of a String更改字符串的大小寫CountMatchescounts the number of occurrences of one String in another計算一個字符串在另一個字符串中出現(xiàn)的次數(shù)IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintablechecks the characters in a String檢查字符串中的字符DefaultStringprotects against a null input String防止輸入字符串為空Rotaterotate (circular shift) a String旋轉(zhuǎn)(循環(huán)移位)字符串Reverse/ReverseDelimitedreverses a String -反轉(zhuǎn)字符串Abbreviateabbreviates a string using ellipsis or another given String使用省略號或另一個給定的String縮寫一個字符串Differencecompares Strings and reports on their differences比較字符串并報告其差異LevenshteinDistancethe number of changes needed to change one String into another將一個String轉(zhuǎn)換為另一個String所需的更改次數(shù)

      來源:https://sourl.cn/dRpJ6b

      鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場,版權(quán)歸原作者所有,如有侵權(quán)請聯(lián)系管理員(admin#wlmqw.com)刪除。
      用戶投稿
      上一篇 2022年7月15日 06:39
      下一篇 2022年7月15日 06:40

      相關(guān)推薦

      • 122交通安全知識線上競賽答題次數(shù)限制嗎?(附獎品設置)

        不限制答題次數(shù) ①掃描下方二維碼進入H5答題頁面,即可開始答題。 ②每日答題次數(shù)不限 ③答題得分90分及以上即可獲得抽獎資格。 ④獲獎名單分別于12月2日、12月12日、12月22…

        2022年11月22日
      • ftp端口號(ftp端口號可以自定義嗎)

        FTP端口號是21在FTP服務器中,我們往往會給不同的部門或者某個特定的用戶設置一個帳戶但是,這個賬戶有個特點,就是其只能夠訪問自己的主目錄服務器通過這種方式來保障FTP服務上其他…

        2022年11月21日
      • 劉愷威承認與李曉峰戀情!甜蜜分享相處日常,病榻中獲其照顧

        沒想到劉愷威的“第二春”來得這么突然,但進展卻非常迅速,由最開始的認錯人,到中途逛寺廟,再到女主變相承認,兩人牽手做核酸等等,這個過程也就一個多月的時間。 11月18號晚,劉愷威在…

        2022年11月20日
      • 暴雪啟動器卡在“正在更新暴雪啟動器”?

        一直卡,用360流量監(jiān)控看到agent連不上服務器,C:\ProgramData\Battle.net\Agent\Agent.1040\Logs里的AgentErrors文件里有…

        2022年11月20日
      • 注冊網(wǎng)站域名注意的3大事項解析(中國域名注冊怎么做)

        隨著互聯(lián)網(wǎng)的發(fā)展和普及,很多企業(yè)和個人都開通了自己的網(wǎng)站,通過網(wǎng)站進行品牌的宣傳和業(yè)務的發(fā)展。而域名作為建站的第一步是至關(guān)重要的。那么我們該如何注冊網(wǎng)站域名呢?在注冊域名時又該注意…

        2022年11月19日
      • 拼多多多人團一周幾次 拼多多多人團可以團幾次?

        拼多多的多人團大家有玩過嗎?價格的話真的是超便宜的,而且產(chǎn)品的質(zhì)量也是無敵了。那大家知道拼多多多人團一周幾次呢?一個月團幾次呢?下面就和小編一起來看看吧。 拼多多多人團一周幾次? …

        2022年11月17日
      • 海外代理服務器(海外代理服務器IP)

        今天小編給各位分享海外代理服務器的知識,其中也會對海外代理服務器IP進行解釋,如果能碰巧解決你現(xiàn)在面臨的問題,別忘了關(guān)注本站,現(xiàn)在開始吧! 代理境外服務器需要什么資質(zhì) 不需要。 代…

        2022年11月15日
      • 8字頭股票什么意思(8字頭股票什么意思呀)

        北京證券交易所股票是以4和8開頭1北京證券交易所是以現(xiàn)有的新三板精選層為基礎組建,進一步提升服務中小企業(yè)的能力,打造服務創(chuàng)新型中小企業(yè)主陣地北京證券交易所是因為我們國家要支持中小企…

        2022年11月11日
      • 如何在抖音開直播流程一覽(如何在抖音開直播放電影)

        抖音直播現(xiàn)在非?;?,很多商家、主播都會在抖音上進行直播賣貨,不過直播賣貨也是有技巧方法的,很多主播可能雖然每天都堅持直播,但是就是沒什么人下單,銷量增長緩慢。那么,我們?nèi)绾卧诙兑糸_…

        2022年11月9日
      • 首選dns(首選dns的服務器地址是多少)

        今天小編給各位分享首選dns的知識,其中也會對首選dns的服務器地址是多少進行解釋,如果能碰巧解決你現(xiàn)在面臨的問題,別忘了關(guān)注本站,現(xiàn)在開始吧! 首選DNS服務器填什么? 填寫11…

        2022年11月9日

      聯(lián)系我們

      聯(lián)系郵箱:admin#wlmqw.com
      工作時間:周一至周五,10:30-18:30,節(jié)假日休息