<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 193,  comments - 520,  trackbacks - 0

      檢查字符串是否為空或null或僅僅包含空格
      String test = "";
      String test1=" ";
      String test2 = "\n\n\t";
      String test3 = null;
      System.out.println( "test blank? " + StringUtils.isBlank( test ) );
      System.out.println( "test1 blank? " + StringUtils.isBlank( test1 ) );
      System.out.println( "test2 blank? " + StringUtils.isBlank( test2 ) );
      System.out.println( "test3 blank? " + StringUtils.isBlank( test3 ) );
      運(yùn)行結(jié)果:
      test blank? true
      test1 blank? true
      test2 blank? true
      test3 blank? true
      相對(duì)應(yīng)的還有一個(gè)StringUtils.isNotBlank(String str)
      StringUtils.isEmpty(String str)則檢查字符串是否為空或null(不檢查是否僅僅包含空格)
     
      分解字符串
      StringUtils.split(null, *, *)            = null
      StringUtils.split("", *, *)              = []
      StringUtils.split("ab de fg", null, 0)   = ["ab", "cd", "ef"]
      StringUtils.split("ab   de fg", null, 0) = ["ab", "cd", "ef"]
      StringUtils.split("ab:cd:ef", ":", 0)    = ["ab", "cd", "ef"]
      StringUtils.split("ab:cd:ef", ":", 1)    = ["ab:cd:ef"]
      StringUtils.split("ab:cd:ef", ":", 2)    = ["ab", "cd:ef"]
      StringUtils.split(String str,String separatorChars,int max) str為null時(shí)返回null
      separatorChars為null時(shí)默認(rèn)為按空格分解,max為0或負(fù)數(shù)時(shí)分解沒(méi)有限制,max為1時(shí)返回整個(gè)字符串,max為分解成的個(gè)數(shù)(大于實(shí)際則無(wú)效)
     
      去除字符串前后指定的字符
      StringUtils.strip(null, *)          = null
      StringUtils.strip("", *)            = ""
      StringUtils.strip("abc", null)      = "abc"
      StringUtils.strip(" abc ", null)    = "abc"
      StringUtils.strip("  abcyx", "xyz") = "  abc"
      StringUtils.strip(String str,String stripChars) str為null時(shí)返回null,stripChars為null時(shí)默認(rèn)為空格

      創(chuàng)建醒目的Header(調(diào)試時(shí)用)
      public String createHeader( String title ) {
        int width = 30;
        String stars = StringUtils.repeat( "*", width);
        String centered = StringUtils.center( title, width, "*" );
        String heading = StringUtils.join(new Object[]{stars, centered, stars}, "\n");
        return heading;
      }
      調(diào)用createHeader("TEST")的輸出結(jié)果:
      ******************************
      ************ TEST ************
      ******************************

      字符的全部反轉(zhuǎn)及以單個(gè)詞為單位的反轉(zhuǎn)
      String original = "In time, I grew tired of his babbling nonsense.";
      StringUtils.reverse( original )   = ".esnesnon gnilbbab sih fo derit werg I ,emit nI"
      以單個(gè)詞為單位的反轉(zhuǎn)
      public Sentence reverseSentence(String sentence) {
        String reversed = StringUtils.chomp( sentence, "." );
        reversed = StringUtils.reverseDelimited( reversed, ' ' );
        reversed = reversed + ".";
        return reversed;
      }
      String sentence = "I am Susan."
      reverseSentence( sentence ) )   = "Susan am I."

      檢查字符串是否僅僅包含數(shù)字、字母或數(shù)字和字母的混合
      String test1 = "ORANGE";
      String test2 = "ICE9";
      String test3 = "ICE CREAM";
      String test4 = "820B Judson Avenue";
      String test5 = "1976";
      結(jié)果:
      boolean t1val = StringUtils.isAlpha( test1 ); // returns true
      boolean t2val = StringUtils.isAlphanumeric( test2 ); // returns true
      boolean t3val = StringUtils.isAlphaSpace( test3 ); // returns true
      boolean t4val = StringUtils.isAlphanumericSpace( test4 ); // returns true
      boolean t5val = StringUtils.isNumeric( test5 ); // returns true



    http://m.tkk7.com/ronghao 榮浩原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處:)
    posted on 2005-12-14 12:47 ronghao 閱讀(2602) 評(píng)論(1)  編輯  收藏 所屬分類: j2se基礎(chǔ)

    FeedBack:
    # re: [Jakarta Commons Cookbook 筆記](méi) StringUtils類使用
    2005-12-14 15:31 | joecom
    StringUtils類確實(shí)挺好用

    上次用String.split分割"|",差點(diǎn)給搞死,原來(lái)用String.split分割像 "|"等一些字符需要用"\\|"來(lái)的

    StringUtils.split這個(gè)就沒(méi)什么問(wèn)題.  回復(fù)  更多評(píng)論
      
    <2005年12月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    關(guān)注工作流和企業(yè)業(yè)務(wù)流程改進(jìn)?,F(xiàn)就職于ThoughtWorks。新浪微博:http://weibo.com/ronghao100

    常用鏈接

    留言簿(38)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    常去的網(wǎng)站

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产裸体美女永久免费无遮挡| 亚洲一欧洲中文字幕在线| 美女露100%胸无遮挡免费观看| 国产成人精品免费视频动漫| 亚洲久本草在线中文字幕| 岛国岛国免费V片在线观看| 亚洲伊人成无码综合网| 男女污污污超污视频免费在线看| 国产男女猛烈无遮挡免费视频网站 | 国产亚洲一区二区三区在线不卡 | 无码日韩精品一区二区三区免费 | 91九色视频无限观看免费| 久久av无码专区亚洲av桃花岛| 久久aa毛片免费播放嗯啊| 久久久无码精品亚洲日韩按摩| 99视频有精品视频免费观看| 久久精品九九亚洲精品| 日韩亚洲国产高清免费视频| 男人天堂2018亚洲男人天堂| 国产成人精品免费直播| 成人午夜免费视频| 国产亚洲人成网站在线观看不卡| 久久爰www免费人成| 亚洲专区一路线二| 在线观看免费人成视频色9| 亚洲乱色伦图片区小说| 亚洲av日韩片在线观看| a级毛片免费高清毛片视频| 2022年亚洲午夜一区二区福利 | 噜噜综合亚洲AV中文无码| 亚洲成A∨人片天堂网无码| 中文字幕免费在线视频| 色拍自拍亚洲综合图区| 午夜一级毛片免费视频| 国产免费MV大全视频网站| 亚洲AV成人片色在线观看| 99视频在线精品免费观看6| 免费看一级高潮毛片| 亚洲av女电影网| 免费无码又爽又刺激高潮 | 67194国产精品免费观看|