<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 ) );
      運行結(jié)果:
      test blank? true
      test1 blank? true
      test2 blank? true
      test3 blank? true
      相對應(yīng)的還有一個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時返回null
      separatorChars為null時默認(rèn)為按空格分解,max為0或負(fù)數(shù)時分解沒有限制,max為1時返回整個字符串,max為分解成的個數(shù)(大于實際則無效)
     
      去除字符串前后指定的字符
      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時返回null,stripChars為null時默認(rèn)為空格

      創(chuàng)建醒目的Header(調(diào)試時用)
      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)及以單個詞為單位的反轉(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"
      以單個詞為單位的反轉(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)載請注明出處:)
    posted on 2005-12-14 12:47 ronghao 閱讀(2593) 評論(1)  編輯  收藏 所屬分類: j2se基礎(chǔ)

    FeedBack:
    # re: [Jakarta Commons Cookbook 筆記] StringUtils類使用
    2005-12-14 15:31 | joecom
    StringUtils類確實挺好用

    上次用String.split分割"|",差點給搞死,原來用String.split分割像 "|"等一些字符需要用"\\|"來的

    StringUtils.split這個就沒什么問題.  回復(fù)  更多評論
      
    <2005年12月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

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

    常用鏈接

    留言簿(38)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    常去的網(wǎng)站

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 91亚洲精品视频| 亚洲日本一区二区| 亚洲精华国产精华精华液好用 | 国产免费毛不卡片| 18gay台湾男同亚洲男同| 免费无码AV片在线观看软件| 叮咚影视在线观看免费完整版| 午夜免费福利视频| 五月天网站亚洲小说| 色欲A∨无码蜜臀AV免费播 | 国产亚洲sss在线播放| 国内大片在线免费看| 日韩欧美亚洲国产精品字幕久久久| 成年人在线免费看视频| 成a人片亚洲日本久久| 亚洲av无码不卡私人影院| 人成免费在线视频| 久久亚洲精品中文字幕三区| 99在线观看精品免费99| 久久综合久久综合亚洲| 日批日出水久久亚洲精品tv| 久久国产精品免费| 亚洲高清无在码在线电影不卡| 一二三四免费观看在线视频中文版| 色欲色欲天天天www亚洲伊| 国产亚洲人成A在线V网站| 精品视频一区二区三区免费| 在线电影你懂的亚洲| 毛片免费全部免费观看| 羞羞视频在线观看免费| 777亚洲精品乱码久久久久久| 最近中文字幕免费mv视频8| 尤物视频在线免费观看| 亚洲一区二区三区日本久久九| 一个人免费观看视频www| 国产亚洲视频在线观看网址| 国产亚洲av片在线观看16女人| 无码成A毛片免费| 亚洲成av人无码亚洲成av人| 亚洲av永久无码精品漫画| 毛片免费观看网址|