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

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

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

    Dust Of Dream

    知識真的是一個圓么?

    ArrayUtils學習筆記

    ArrayUtils 擁有以下方法:
    toString
    將一個數(shù)組轉(zhuǎn)換成String,用于打印數(shù)組
    isEquals
    判斷兩個數(shù)組是否相等,采用EqualsBuilder進行判斷
    toMap
    將一個數(shù)組轉(zhuǎn)換成Map,如果數(shù)組里是Entry則其Key與Value就是新Map的Key和Value,如果是Object[]則Object[0]為KeyObject[1]為Value
    clone
    拷貝數(shù)組
    subarray
    截取子數(shù)組
    isSameLength
    判斷兩個數(shù)組長度是否相等
    getLength
    獲得數(shù)組的長度
    isSameType
    判段兩個數(shù)組的類型是否相同
    reverse
    數(shù)組反轉(zhuǎn)
    indexOf
    查詢某個Object在數(shù)組中的位置,可以指定起始搜索位置
    lastIndexOf
    反向查詢某個Object在數(shù)組中的位置,可以指定起始搜索位置
    contains
    查詢某個Object是否在數(shù)組中
    toObject
    將基本數(shù)據(jù)類型轉(zhuǎn)換成外包型數(shù)據(jù)
    isEmpty
    判斷數(shù)組是否為空(null和length=0的時候都為空)
    addAll
    合并兩個數(shù)組
    add
    添加一個數(shù)據(jù)到數(shù)組
    remove
    刪除數(shù)組中某個位置上的數(shù)據(jù)
    removeElement
    刪除數(shù)組中某個對象(從正序開始搜索,刪除第一個)
    eg:
            // 1.打印數(shù)組
            ArrayUtils.toString(new int[] { 1423 });// {1,4,2,3}
            ArrayUtils.toString(new Integer[] { 1423 });// {1,4,2,3}
            ArrayUtils.toString(null"I'm nothing!");// I'm nothing!

            
    // 2.判斷兩個數(shù)組是否相等,采用EqualsBuilder進行判斷
            
    // 只有當兩個數(shù)組的數(shù)據(jù)類型,長度,數(shù)值順序都相同的時候,該方法才會返回True
            
    // 2.1 兩個數(shù)組完全相同
            ArrayUtils.isEquals(new int[] { 123 }, new int[] { 123 });// true
            
    // 2.2 數(shù)據(jù)類型以及長度相同,但各個Index上的數(shù)據(jù)不是一一對應
            ArrayUtils.isEquals(new int[] { 132 }, new int[] { 123 });// true
            
    // 2.3 數(shù)組的長度不一致
            ArrayUtils.isEquals(new int[] { 1233 }, new int[] { 123 });// false
            
    // 2.4 不同的數(shù)據(jù)類型
            ArrayUtils.isEquals(new int[] { 123 }, new long[] { 123 });// false
            ArrayUtils.isEquals(new Object[] { 123 }, new Object[] { 1, (long23 });// false
            
    // 2.5 Null處理,如果輸入的兩個數(shù)組都為null時候則返回true
            ArrayUtils.isEquals(new int[] { 123 }, null);// false
            ArrayUtils.isEquals(nullnull);// true

            
    // 3.將一個數(shù)組轉(zhuǎn)換成Map
            
    // 如果數(shù)組里是Entry則其Key與Value就是新Map的Key和Value,如果是Object[]則Object[0]為KeyObject[1]為Value
            
    // 對于Object[]數(shù)組里的元素必須是instanceof Object[]或者Entry,即不支持基本數(shù)據(jù)類型數(shù)組
            
    // 如:ArrayUtils.toMap(new Object[]{new int[]{1,2},new int[]{3,4}})會出異常
            ArrayUtils.toMap(new Object[] { new Object[] { 12 }, new Object[] { 34 } });// {1=2,
            
    // 3=4}
            ArrayUtils.toMap(new Integer[][] { new Integer[] { 12 }, new Integer[] { 34 } });// {1=2,
            
    // 3=4}

            
    // 4.拷貝數(shù)組
            ArrayUtils.clone(new int[] { 324 });// {3,2,4}

            
    // 5.截取數(shù)組
            ArrayUtils.subarray(new int[] { 34156 }, 24);// {1,5}
            
    // 起始index為2(即第三個數(shù)據(jù))結(jié)束index為4的數(shù)組
            ArrayUtils.subarray(new int[] { 34156 }, 210);// {1,5,6}
            
    // 如果endIndex大于數(shù)組的長度,則取beginIndex之后的所有數(shù)據(jù)

            
    // 6.判斷兩個數(shù)組的長度是否相等
            ArrayUtils.isSameLength(new Integer[] { 135 }, new Long[] { 2L8L10L });// true

            
    // 7.獲得數(shù)組的長度
            ArrayUtils.getLength(new long[] { 1233 });// 3

            
    // 8.判段兩個數(shù)組的類型是否相同
            ArrayUtils.isSameType(new long[] { 13 }, new long[] { 856 });// true
            ArrayUtils.isSameType(new int[] { 13 }, new long[] { 856 });// false

            
    // 9.數(shù)組反轉(zhuǎn)
            int[] array = new int[] { 125 };
            ArrayUtils.reverse(array);
    // {5,2,1}

            
    // 10.查詢某個Object在數(shù)組中的位置,可以指定起始搜索位置,找不到返回-1
            
    // 10.1 從正序開始搜索,搜到就返回當前的index否則返回-1
            ArrayUtils.indexOf(new int[] { 136 }, 6);// 2
            ArrayUtils.indexOf(new int[] { 136 }, 2);// -1
            
    // 10.2 從逆序開始搜索,搜到就返回當前的index否則返回-1
            ArrayUtils.lastIndexOf(new int[] { 136 }, 6);// 2

            
    // 11.查詢某個Object是否在數(shù)組中
            ArrayUtils.contains(new int[] { 312 }, 1);// true
            
    // 對于Object數(shù)據(jù)是調(diào)用該Object.equals方法進行判斷
            ArrayUtils.contains(new Object[] { 312 }, 1L);// false

            
    // 12.基本數(shù)據(jù)類型數(shù)組與外包型數(shù)據(jù)類型數(shù)組互轉(zhuǎn)
            ArrayUtils.toObject(new int[] { 12 });// new Integer[]{Integer,Integer}
            ArrayUtils.toPrimitive(new Integer[] { new Integer(1), new Integer(2) });// new int[]{1,2}

            
    // 13.判斷數(shù)組是否為空(null和length=0的時候都為空)
            ArrayUtils.isEmpty(new int[0]);// true
            ArrayUtils.isEmpty(new Object[] { null });// false

            
    // 14.合并兩個數(shù)組
            ArrayUtils.addAll(new int[] { 135 }, new int[] { 24 });// {1,3,5,2,4}

            
    // 15.添加一個數(shù)據(jù)到數(shù)組
            ArrayUtils.add(new int[] { 135 }, 4);// {1,3,5,4}

            
    // 16.刪除數(shù)組中某個位置上的數(shù)據(jù)
            ArrayUtils.remove(new int[] { 135 }, 1);// {1,5}

            
    // 17.刪除數(shù)組中某個對象(從正序開始搜索,刪除第一個)
            ArrayUtils.removeElement(new int[] { 135 }, 3);// {1,5}

    posted on 2008-02-26 18:23 Anemone 閱讀(11082) 評論(6)  編輯  收藏 所屬分類: 牧羊心得

    Feedback

    # re: ArrayUtils學習筆記[未登錄] 2008-02-26 20:00 eric

    pls check out java.util.collection.Arrays  回復  更多評論   

    # re: ArrayUtils學習筆記 2008-02-26 22:36 ZelluX

    其實覺得這樣學效果不好,看了就忘。  回復  更多評論   

    # re: ArrayUtils學習筆記 2008-02-27 10:20 Anemone

    @ZelluX
    我一般習慣于用代碼記錄心得,我自己有專門的Google項目,里面有自己工作時候遇到的難題或者實現(xiàn)方案的示例代碼,發(fā)到博客里主要是方便搜索^^  回復  更多評論   

    # re: ArrayUtils學習筆記 2008-02-28 15:59 離弦之ray的技術(shù)天空

    clone是深拷貝還是淺拷貝??  回復  更多評論   

    # re: ArrayUtils學習筆記 2009-02-05 09:23 ss

    看了就忘記,最高境界。呵呵。  回復  更多評論   

    # re: ArrayUtils學習筆記[未登錄] 2014-11-20 22:28 xx

    @離弦之ray的技術(shù)天空
    淺,看下源碼就知道了  回復  更多評論   


    My Links

    Blog Stats

    News

    常用鏈接

    留言簿(1)

    隨筆分類

    隨筆檔案

    新聞檔案

    相冊

    常去網(wǎng)站

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产一级一片免费播放| 国产av天堂亚洲国产av天堂| 免费无码婬片aaa直播表情| 亚洲无人区一区二区三区| 69视频免费观看l| 18禁亚洲深夜福利人口| 亚洲人成网站在线观看播放| 四虎在线视频免费观看视频| 亚洲JIZZJIZZ妇女| 精品亚洲永久免费精品| 久久久www成人免费毛片| 9久热这里只有精品免费| 亚洲精品国产国语| 亚洲精品卡2卡3卡4卡5卡区| 成人免费视频试看120秒| 免费萌白酱国产一区二区三区| 亚洲AV色吊丝无码| 国产午夜亚洲不卡| 成人一a毛片免费视频| 中文字幕一区二区三区免费视频| 国产精品高清视亚洲精品| 亚洲精品亚洲人成在线观看| 免费a级毛片高清视频不卡| a级午夜毛片免费一区二区| 亚洲av无码一区二区三区天堂| 久久精品国产精品亚洲蜜月| 免费无码不卡视频在线观看| 国产精品免费福利久久| 深夜A级毛片视频免费| 亚洲综合色7777情网站777| 亚洲va中文字幕无码久久| 免费一区二区三区四区五区| 四虎1515hh永久久免费| 爽爽爽爽爽爽爽成人免费观看| 亚洲精品日韩一区二区小说| 久久久亚洲欧洲日产国码二区| 久久乐国产精品亚洲综合| 国产免费牲交视频| 永久黄网站色视频免费直播| 日韩吃奶摸下AA片免费观看| 五月亭亭免费高清在线|