国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

org.apache.commons.lang3工具類使用

這篇具有很好參考價值的文章主要介紹了org.apache.commons.lang3工具類使用。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

org.apache.commons.lang3工具類使用

首先需要引入依賴

		<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>

常用方法如下:文章來源地址http://www.zghlxwxcb.cn/news/detail-524452.html

	/**
     *org.apache.commons.lang3.StringUtils 方法
     */
    @Test
    void contextLoads() throws ParseException, InterruptedException {
        // ************************ 字符串 ***********************************
        // 有一個為空則為true
        System.out.println("isAnyBlank:" + StringUtils.isAnyBlank("","4","5"));
        // 全部不為空則為true
        System.out.println("isNoneBlank:" + StringUtils.isNoneBlank("4","5"));
        // 全部為空則為true
        System.out.println("isAllBlank:" + StringUtils.isAllBlank(""," "));
        // 如果字符串尚未以后綴結(jié)尾,則在字符串結(jié)尾追加后綴
        System.out.println("appendIfMissing:" + StringUtils.appendIfMissing("hello","@")); // hello@
        // 指定字符串不以某段字符串開頭,則自動添加開頭
        System.out.println("prependIfMissing :" + StringUtils.prependIfMissing("hello","@")); // @hello
        // 判斷字符串是否以什么結(jié)尾
        System.out.println("endsWith:" + StringUtils.endsWith("abcd.s@","@"));
        /**
         *  截取字符串做一個縮減操作  固定占位符 ... 站三個寬度
         *  也就是最終會有三個點,最大寬度為總共幾個包括...
         *  且最大寬度最小為4,如果最大長度大于等于 源字符串則不生效相當于沒有進行操作
         */
        System.out.println("abbreviate:" + StringUtils.abbreviate("測試字 符串", 6)); // abbreviate:測...
        System.out.println("abbreviate:" + StringUtils.abbreviate("abcd.s@", 5)); // abbreviate:ab...
        // 首字母轉(zhuǎn)大寫
        System.out.println("capitalize:" + StringUtils.capitalize("abcd.s@"));
        // 首字母轉(zhuǎn)小寫
        System.out.println("uncapitalize:" + StringUtils.uncapitalize("abcd.s@"));
        // 字符串中間填充(長度包含源字符串長度)
        System.out.println("center :" + StringUtils.center("測試字 符串",8,"*"));
        // 字符串左填充
        System.out.println("leftPad :" + StringUtils.leftPad("測試字 符串",5,"*"));
        // 字符串右填充
        System.out.println("rightPad :" + StringUtils.rightPad("測試字 符串",6,"*"));
        // 從字符串中刪除最后一個換行符\n、\r、\r\n
        System.out.println("chomp :" + StringUtils.chomp("abcd.@569 \r"));
        // 剔除字符串最后一個字符(如果最后一個是\n或\r\或\r\n也剔除掉)
        System.out.println("chop :" + StringUtils.chop("abcd.@569 \r"));
        // 刪除字符串中的空白全部 java 的trim只去除首尾的
        System.out.println("deleteWhitespace :" + StringUtils.deleteWhitespace("測試字 符串"));
        // 比較兩個字符串,并返回第二個字符串的剩余部分,從它與第一個不同的地方開始
        System.out.println("difference :" + StringUtils.difference("abcd.s@","abcd.@569 \r"));
        // 獲得多個字符串相同的開頭內(nèi)容,接收參數(shù)為多個字符串
        System.out.println("getCommonPrefix :" + StringUtils.getCommonPrefix("abc","ac","abcd")); // a
        // 獲取字符串中的數(shù)字
        System.out.println("getDigits :" + StringUtils.getDigits("ckds123456cs6.9dkcm")); // 12345669
        // 給字符串數(shù)組添加知道分隔符
        System.out.println("joinWith :" + StringUtils.joinWith(",","abc25","abc")); // abc25,abc
        // 字符串截取相當于substring,不同在于當截取字符超過源字符串長度不會報錯
        System.out.println("mid :" + StringUtils.mid("asdfg",1,8)); // sdfg
        // 用另一個字符串覆蓋字符串的一部分(指定區(qū)域)
        System.out.println("overlay :" + StringUtils.overlay("abcdef", "zzzz", 2, 4)); // abzzzzef
        //替換字符串內(nèi)容……等同于java 原生 replace()和 replaceFirst()
        System.out.println("replace :" + StringUtils.replace("aba", "a", "z")); // zbz
        System.out.println("replaceOnce :" + StringUtils.replaceOnce("aba", "a", "z")); // zba
        // //統(tǒng)計一字符串在另一字符串中出現(xiàn)次數(shù)
        System.out.println("countMatches :" + StringUtils.countMatches("dcabcfccrt","c")); // 4
        // 刪除字符串中的指定內(nèi)容
        System.out.println("remove :" + StringUtils.remove("abcdef","c")); // abdef
        // 刪除字符串中結(jié)尾(滿足是以某段內(nèi)容結(jié)尾)
        System.out.println("removeEnd :" + StringUtils.removeEnd("abcdef","ef")); // abcd
        // 刪除字符串中開頭(滿足是以某段內(nèi)容開始)
        System.out.println("removeStart :" + StringUtils.removeStart("abcdef","a")); // bcdef
        // //重復(fù)字符/字符串
        System.out.println("repeat :" + StringUtils.repeat("abcdef",5)); // abcdefabcdefabcdefabcdefabcdef
        // 字符串翻轉(zhuǎn)
        System.out.println("reverse :" + StringUtils.reverse("abcdef")); // fedcba
        // 根據(jù)指定分隔符進行反轉(zhuǎn),分隔符之間的字符不進行反轉(zhuǎn)
        System.out.println("reverseDelimited :" + StringUtils.reverseDelimited("abc,def",',')); // def,abc
        // 將字符串后面指定個數(shù)的字符翻轉(zhuǎn)到前面
        System.out.println("rotate :" + StringUtils.rotate("abc,defgfd",3)); // gfdabc,def
        // 截取指定字符串前面的內(nèi)容
        System.out.println("substringBefore :" + StringUtils.substringBefore("abcba", "b")); // a
        // 截取最后指定字符串前面的內(nèi)容
        System.out.println("substringBeforeLast :" + StringUtils.substringBeforeLast("abcba", "b")); // abc
        // 截取指定字符串后面的內(nèi)容
        System.out.println("substringAfter :" + StringUtils.substringAfter("abcba", "b")); // cab
        // 截取最后指定字符串后面的內(nèi)容
        System.out.println("substringAfterLast :" + StringUtils.substringAfterLast("abcba", "b")); // a
        // 截取指定字符串中間的內(nèi)容
        System.out.println("substringBetween :" + StringUtils.substringBetween("tagabctag", "tag")); // abc
        System.out.println("substringBetween :" + StringUtils.substringBetween("yabczyabcz", "y", "z")); // abc
        // 截斷字符串 最大寬度科超過源字符串長度不會報錯
        System.out.println("truncate :" + StringUtils.truncate("abcba",6)); // abcba
        // 判斷字符串數(shù)字
        System.out.println("isNumeric :" + StringUtils.isNumeric("12 3")); // false
        System.out.println("isNumericSpace :" + StringUtils.isNumericSpace("12 3")); // true
        // 判斷字符串是否只有字母和數(shù)字組成 漢字可通過
        System.out.println("isAlphanumeric :" + StringUtils.isAlphanumeric("12xs好j3")); // true
        // 判斷字符串是否只有字母和數(shù)字和空格組成 漢字可通過
        System.out.println("isAlphanumericSpace :" + StringUtils.isAlphanumericSpace("12xs 好j3")); // true
        // 字符串截取,不會忽略空數(shù)據(jù)
        System.out.println("splitByWholeSeparator :" + Arrays.asList(StringUtils.splitByWholeSeparator("12x,s 好j3,,", ","))); // [12x, s 好j3, ]

        // ************************ 數(shù)字 ***********************************
        // //判斷字符串是否全是整數(shù)
        System.out.println("isDigits :" + NumberUtils.isDigits("12.3")); // false
        //從數(shù)組中選出最大值
        System.out.println("max :" + NumberUtils.max(1, 2, 3, 4)); // 4
        //從數(shù)組中選出最小值
        System.out.println("min :" + NumberUtils.min(1, 2, 3, 4)); // 1
        //將一個字符串轉(zhuǎn)換為int類型,失敗返回0
        System.out.println("toInt :" + NumberUtils.toInt("123")); // 123
        //將一個字符串轉(zhuǎn)換為int類型,失敗返回自定義
        System.out.println("toDouble :" + NumberUtils.toDouble("123.1", 0)); // 123.1
        //將一個字符串轉(zhuǎn)換為BigDecimal,自定義小數(shù)位數(shù),自定義舍入模式,默認保留2位小數(shù),舍入模式為RoundingMode.HALF_EVEN
        System.out.println("toScaledBigDecimal :" + NumberUtils.toScaledBigDecimal("2.1", 2, RoundingMode.HALF_UP)); // 2.10
        // ,判斷一個字符串是否可轉(zhuǎn)化為數(shù)字isParsable / isCreatable
        System.out.println("isParsable :" + NumberUtils.isParsable("3.26")); // true
        System.out.println("isCreatable :" + NumberUtils.isCreatable("3.26")); // true

        // ************************ 數(shù)組 ***********************************
        //創(chuàng)建數(shù)組
        String[] array = ArrayUtils.toArray("1", "2");
        System.out.println("判斷數(shù)組中是否包含某一對象 :" + ArrayUtils.contains(array, "33"));

        // ************************ 日期工具 ***********************************
        System.out.println("Date 轉(zhuǎn)化為字符串 :" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        System.out.println("字符串 轉(zhuǎn) Date :" + DateUtils.parseDate("2022-12-19 22:00:00", "yyyy-MM-dd HH:mm:ss"));

        Date now = new Date();
        Date addDays = DateUtils.addDays(now, 1);
        System.out.println("Date 加 1 天 :" + addDays);
        Date addMinutes = DateUtils.addMinutes(now, 30);
        System.out.println("Date 加 30 分鐘 :" + addMinutes);
        Date addSeconds = DateUtils.addSeconds(now, -180);
        System.out.println("Date 減去 180 秒 :" + addSeconds);
        System.out.println("http:// 判斷是否 為 同一天 :" + DateUtils.isSameDay(addDays, addMinutes));
        // 過濾時分秒,若 now 為 2020-05-07 22:13:00 調(diào)用 truncate 方法以后
        // 返回時間為 2020-05-07 00:00:00
        Date truncate = DateUtils.truncate(now, Calendar.DATE);

        // ************************ 時間計算 ***********************************
        // 創(chuàng)建之后立刻計時
        StopWatch watch = StopWatch.createStarted();
        // 若想主動開始計時,創(chuàng)建計時器,調(diào)用 start 方法開始計時
        StopWatch watch1 = StopWatch.create();
        watch1.start();
        // 模擬其他代碼耗時
        TimeUnit.SECONDS.sleep(2L);

        System.out.println("統(tǒng)計從開始到現(xiàn)在運行時間:" + watch.getTime() + "ms"); //2000ms

        TimeUnit.SECONDS.sleep(2L);
        watch.split();
        System.out.println("從start到此刻為止的時間:" + watch.getTime()); //4000
        System.out.println("從開始到第一個切入點運行時間:" + watch.getSplitTime()); //4000

        Thread.sleep(1000);
        watch.split();
        System.out.println("從開始到第二個切入點運行時間:" + watch.getSplitTime()); //5001

        watch.reset(); //重置后必須使用start方法
        watch.start();
        Thread.sleep(1000);
        System.out.println("重新開始后到當前運行時間是:" + watch.getTime()); //1000

        watch.suspend(); //暫停
        Thread.sleep(6000); //模擬暫停6秒鐘

        watch.resume(); //上面suspend,這里要想重新統(tǒng)計,需要恢復(fù)一下
        System.out.println("恢復(fù)后執(zhí)行的時間是:" + watch.getTime()); //1000  注意此時這個值還是1000

        watch.stop();
        System.out.println("花費的時間 ==>" + watch.getTime() + "ms"); //1000ms
        System.out.println("花費的時間 ==>" + watch.getTime(TimeUnit.SECONDS) + "s"); //1s 可以直接轉(zhuǎn)成s
    }

到了這里,關(guān)于org.apache.commons.lang3工具類使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/ToXContentObject

    java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/ToXContentObject

    1.初學(xué)整合ElasticSearch,創(chuàng)建好Configuration測試報錯。 2.解決方法 ? ? ? ? 在pom文件中指定es版本,需和引入的RestHighLevelClient版本一致 3.更新Maven,完美解決

    2024年02月09日
    瀏覽(22)
  • apache-commons-lang3 的基本使用

    apache-commons-lang3 的基本使用

    更多用法

    2024年01月20日
    瀏覽(52)
  • JAVA深化篇_26——Apache commons-io工具包的使用

    Apache基金會介紹 Apache軟件基金會(也就是Apache Software Foundation,簡稱為ASF),是專門為支持開源軟件項目而辦的一個非盈利性組織。在它所支持的Apache項目與子項目中,所發(fā)行的軟件產(chǎn)品都遵循Apache許可證(Apache License)。 官方網(wǎng)址為:www.apache.org 。 很多著名的Java開源項目

    2024年02月06日
    瀏覽(69)
  • 錯誤-maven工程,程序包org.apache.commons.xxx不存在,Java:不支持發(fā)行版本5

    錯誤-maven工程,程序包org.apache.commons.xxx不存在,Java:不支持發(fā)行版本5

    因為最新的idea界面中文支持較好,就更新了idea,但是發(fā)現(xiàn)在導(dǎo)入以前的項目時報了兩個錯誤 程序包org.apache.commons.xxx不存在, Java:不支持發(fā)行版本5 那就逐個解決一下 原因就一個,從Java 9開始,以后的編譯器無法再生成Java 5二進制文件 Java及其虛擬機高度向后兼容,可以使

    2024年02月01日
    瀏覽(38)
  • 完美解決org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

    已解決org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp 下滑查看解決方法 org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp 對于出現(xiàn)org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp的錯誤,有幾種可能的解決

    2024年02月09日
    瀏覽(16)
  • 解決 java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader 報錯

    解決 java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader 報錯

    在使用POI導(dǎo)出Excel表格的時候,本地運行導(dǎo)出沒問題,但是發(fā)布到服務(wù)器后提示 “java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader” 下面是pom.xml中的配置 一開始以為缺少jar包導(dǎo)致的,后來排查發(fā)現(xiàn)不是這個原因,是因為ooxml-schemas版本過低。對于poi 4.1.0和4.1.2來說,應(yīng)該使用

    2024年01月21日
    瀏覽(37)
  • java.lang.NoClassDefFoundError: org.apache.poi.POIXMLDocument問題排查解決

    java.lang.NoClassDefFoundError: org.apache.poi.POIXMLDocument問題排查解決

    項目打包部署完成,用jar包在部署環(huán)境運行,在使用到poi相關(guān)的服務(wù)時報錯 java.lang.NoClassDefFoundError: org.apache.poi.POIXMLDocument 然后我查找了些解決辦法,對處理方法做了梳理: 使用XSSWorkbook,使用時出錯 pom文件少引入依賴 包依賴沖突 使用模塊沒有聲明所需依賴(這是我遇到的

    2024年02月06日
    瀏覽(25)
  • easyexcel導(dǎo)出報錯 java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader

    easyexcel導(dǎo)出報錯 java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader

    報錯: 原因: 這是因為poi依賴不一致導(dǎo)致的,將poi各個依賴換成一直就行 我的是easyexcel 2.2.7版本 對應(yīng)poi三個依賴4.1.2,替換后問題解決

    2024年02月04日
    瀏覽(61)
  • Java工具庫——commons-lang3的50個常用方法

    Java工具庫——commons-lang3的50個常用方法

    未來的你,我親愛的女孩,愿此刻無憂無慮,開心,快樂… Apache Commons Lang 3(通常簡稱為Commons Lang 3)是Apache Commons項目中的一個Java工具庫,它提供了一系列實用的工具類和方法,用于簡化和增強Java編程中常見的任務(wù)。Commons Lang 3主要關(guān)注文本處理、日期操作、數(shù)學(xué)計算、系

    2024年02月07日
    瀏覽(19)
  • java.lang.ClassNotFoundException: org.apache.jsp.index_jsp報錯:已解決

    java.lang.ClassNotFoundException: org.apache.jsp.index_jsp報錯:已解決

    運行時出現(xiàn)`java.lang.ClassNotFoundException: org.apache.jsp.index_jsp`報錯是因為:我們在jsp頁面中使用了jstl標簽,但是沒有引入jstl相關(guān)的jar包。 在運行項目時發(fā)現(xiàn)有后端錯誤,如圖: ?發(fā)現(xiàn)jsp頁面中使用的jstl標簽有警告提示: %@ taglib prefix=\\\"c\\\" uri=\\\"http://java.sun.com/jsp/jstl/core\\\" % ?發(fā)現(xiàn)項目

    2024年02月06日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包