在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    isEmpty 和 isBlank 請(qǐng)別亂用了,小心把服務(wù)器搞崩

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

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

    isEmpty系列

    StringUtils.isEmpty()

    是否為空. 可以看到 ” ” 空格是會(huì)繞過(guò)這種空格判斷,因?yàn)槭且粋€(gè)空格,并不是嚴(yán)格的空值,會(huì)導(dǎo)致 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()

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

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

    StringUtils.isAnyEmpty()

    是否有一個(gè)為空,只有一個(gè)為空,就為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()

    相當(dāng)于!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()

    是否真的不為空,不是空格或者空值 ,相當(dāng)于!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的其他方法

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

    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刪除前導(dǎo)和尾隨空格Equals/Comparecompares two strings null-safe比較兩個(gè)字符串是否為null安全的startsWithcheck if a String starts with a prefix null-safe檢查字符串是否以前綴null安全開(kāi)頭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字符串是否僅包含/無(wú)/這些字符中的任何一個(gè)Substring/Left/Right/Midnull-safe substring extractions字符串安全提取SubstringBefore/SubstringAfter/SubstringBetweensubstring extraction relative to other strings -相對(duì)其他字符串的字符串提取Split/Joinsplits a String into an array of substrings and vice versa將字符串拆分為子字符串?dāng)?shù)組,反之亦然Remove/Deleteremoves part of a String -刪除字符串的一部分Replace/OverlaySearches a String and replaces one String with another搜索字符串,然后用另一個(gè)字符串替換Chomp/Chopremoves the last part of a String刪除字符串的最后一部分AppendIfMissingappends a suffix to the end of the String if not present如果不存在后綴,則在字符串的末尾附加一個(gè)后綴PrependIfMissingprepends a prefix to the start of the String if not present如果不存在前綴,則在字符串的開(kāi)頭添加前綴LeftPad/RightPad/Center/Repeatpads a String填充字符串UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalizechanges the case of a String更改字符串的大小寫(xiě)CountMatchescounts the number of occurrences of one String in another計(jì)算一個(gè)字符串在另一個(gè)字符串中出現(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使用省略號(hào)或另一個(gè)給定的String縮寫(xiě)一個(gè)字符串Differencecompares Strings and reports on their differences比較字符串并報(bào)告其差異LevenshteinDistancethe number of changes needed to change one String into another將一個(gè)String轉(zhuǎn)換為另一個(gè)String所需的更改次數(shù)

    來(lái)源:https://sourl.cn/dRpJ6b

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

    相關(guān)推薦

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

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

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

      FTP端口號(hào)是21在FTP服務(wù)器中,我們往往會(huì)給不同的部門或者某個(gè)特定的用戶設(shè)置一個(gè)帳戶但是,這個(gè)賬戶有個(gè)特點(diǎn),就是其只能夠訪問(wèn)自己的主目錄服務(wù)器通過(guò)這種方式來(lái)保障FTP服務(wù)上其他…

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

      沒(méi)想到劉愷威的“第二春”來(lái)得這么突然,但進(jìn)展卻非常迅速,由最開(kāi)始的認(rèn)錯(cuò)人,到中途逛寺廟,再到女主變相承認(rèn),兩人牽手做核酸等等,這個(gè)過(guò)程也就一個(gè)多月的時(shí)間。 11月18號(hào)晚,劉愷威在…

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

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

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

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

      2022年11月19日
    • 拼多多多人團(tuán)一周幾次 拼多多多人團(tuán)可以團(tuán)幾次?

      拼多多的多人團(tuán)大家有玩過(guò)嗎??jī)r(jià)格的話真的是超便宜的,而且產(chǎn)品的質(zhì)量也是無(wú)敵了。那大家知道拼多多多人團(tuán)一周幾次呢?一個(gè)月團(tuán)幾次呢?下面就和小編一起來(lái)看看吧。 拼多多多人團(tuán)一周幾次? …

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

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

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

      北京證券交易所股票是以4和8開(kāi)頭1北京證券交易所是以現(xiàn)有的新三板精選層為基礎(chǔ)組建,進(jìn)一步提升服務(wù)中小企業(yè)的能力,打造服務(wù)創(chuàng)新型中小企業(yè)主陣地北京證券交易所是因?yàn)槲覀儑?guó)家要支持中小企…

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

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

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

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

      2022年11月9日

    聯(lián)系我們

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