commons-lang3工具类学习(一)
一、ArchUtils
java運行環境的系統信息工具類
getArch();// 獲取電腦處理器體系結構 32 bit、64 bit、unknown getType();// 返回處理器類型 x86、ia64、ppc、unknown is32Bit();// 檢查處理器是否為32位 is64Bit();// 檢查處理器是否為64位 isIA64();// 檢查是否是英特爾安騰處理器類型 isPPC();// 檢查處理器是否是電源PC類型 isX86();// 檢查處理器是否是x86類型二、ArrayUtils
數組工具類
add(boolean[] array, boolean element)?將給定的數據添加到指定的數組中,返回一個新的數組
ArrayUtils.add(null, true) = [true] ArrayUtils.add([true], false) = [true, false] ArrayUtils.add([true, false], true) = [true, false, true]add(boolean[] array, int index, boolean element)?將給定的數據添加到指定的數組下標中,返回一個新的數組。
ArrayUtils.add(null, 0, true) = [true] ArrayUtils.add([true], 0, false) = [false, true] ArrayUtils.add([false], 1, true) = [false, true] ArrayUtils.add([true, false], 1, true) = [true, true, false]byte, int, char, double, float, int, long ,short, T[] 同理
addAll(boolean[] array1, boolean... array2)?將給定的多個數據添加到指定的數組中,返回一個新的數組
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []byte, int, char, double, float, int, long ,short, T[] 同理
clone(boolean[] array)?復制數組并返回 結果數組為空將返回空
byte, int, char, double, float, int, long ,short, T[] 同理
contains(boolean[] array, boolean valueToFind)?檢查該數據在該數組中是否存在,返回一個boolean值
byte, int, char, double, float, int, long ,short, Object 同理
getLength(Object array)?返回該數組長度
ArrayUtils.getLength(null) = 0 ArrayUtils.getLength([]) = 0 ArrayUtils.getLength([null]) = 1 ArrayUtils.getLength([true, false]) = 2 ArrayUtils.getLength([1, 2, 3]) = 3 ArrayUtils.getLength(["a", "b", "c"]) = 3hashCode(Object array)?返回該數組的哈希Code碼
indexOf(boolean[] array, boolean valueToFind)?從數組的第一位開始查詢該數組中是否有指定的數值,存在返回index的數值,否則返回-1
indexOf(boolean[] array, boolean valueToFind, int startIndex)?從數組的第startIndex位開始查詢該數組中是否有指定的數值,存在返回index的數值,否則返回-1
byte, int, char, double, float, int, long ,short 同理
insert(int index, boolean[] array, boolean... values)?向指定的位置往該數組添加指定的元素,返回一個新的數組
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = nullbyte, int, char, double, float, int, long ,short, T[] 同理
isEmpty(boolean[] array)?判斷該數組是否為空,返回一個boolean值
byte, int, char, double, float, int, long ,short, Object 同理
isNotEmpty(boolean[] array)?判斷該數組是否為空,而不是null
byte, int, char, double, float, int, long ,short, T[] 同理
isSameLength(boolean[] array1, boolean[] array2)?判斷兩個數組的長度是否一樣,當數組為空視長度為0。返回一個boolean值
isSameType(Object array1, Object array2)?判斷兩個數組的類型是否一樣,返回一個boolean值
isSorted(boolean[] array)?判斷該數組是否按照自然排列順序排序,返回一個boolean值
byte, int, char, double, float, int, long ,short, T[] 同理
isSorted(T[] array, Comparator<T> comparator)?判斷該數組是否按照比較器排列順序排序,返回一個boolean值
lastIndexOf(boolean[] array, boolean valueToFind)?從數組的最后一位開始往前查詢該數組中是否有指定的數值,存在返回index的數值,否則返回-1
lastIndexOf(boolean[] array, boolean valueToFind, int startIndex)?從數組的最后startIndex位開始往前查詢該數組中是否有指定的數值,存在返回index的數值,否則返回-1
byte, int, char, double, float, int, long ,short, Object 同理
nullToEmpty(boolean[] array)?將null轉換為空的數組,如果數組不為null,返回原數組,如果數組為null,返回一個空的數組
byte, int, char, double, float, int, long ,short, Object, T 同理
remove(boolean[] array, int index)?刪除該數組指定位置上的元素,返回一個新的數組,所有后續元素左移(下標減1)
ArrayUtils.remove([true], 0) = [] ArrayUtils.remove([true, false], 0) = [false] ArrayUtils.remove([true, false], 1) = [true] ArrayUtils.remove([true, true, false], 1) = [true, false]byte, int, char, double, float, int, long ,short, T[] 同理
removeAll(boolean[] array, int... indices)?刪除該數組多個指定位置上的元素,返回一個新的數組,所有后續元素左移(下標減1)
ArrayUtils.removeAll([true, false, true], 0, 2) = [false] ArrayUtils.removeAll([true, false, true], 1, 2) = [true]byte, int, char, double, float, int, long ,short, T[] 同理
removeAllOccurences(boolean[] array, boolean element)?從該數組中刪除指定的元素,返回一個新的數組
byte, int, char, double, float, int, long ,short, T[] 同理
removeElement(boolean[] array, boolean element)?從該數組中刪除指定的元素,返回一個新的數組
byte, int, char, double, float, int, long ,short, T[] 同理
removeElements(boolean[] array, boolean... values)?從該數組中刪除指定數量的元素,返回一個新的數組
ArrayUtils.removeElements(null, true, false) = null ArrayUtils.removeElements([], true, false) = [] ArrayUtils.removeElements([true], false, false) = [true] ArrayUtils.removeElements([true, false], true, true) = [false] ArrayUtils.removeElements([true, false, true], true) = [false, true] ArrayUtils.removeElements([true, false, true], true, true) = [false]byte, int, char, double, float, int, long ,short, T[] 同理
reverse(boolean[] array)?數組反轉
reverse(boolean[] array, int startIndexInclusive, int endIndexExclusive)?數組從指定位置區間進行反轉
byte, int, char, double, float, int, long ,short, Object 同理
shuffle(boolean[] array)?把數組中的元素按隨機順序重新排列
byte, int, char, double, float, int, long ,short, Object 同理
subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)?截取數組,按指定位置區間截取并返回一個新的數組
byte, int, char, double, float, int, long ,short, T[] 同理
swap(boolean[] array, int offset1, int offset2)?指定該數組的兩個位置的元素交換進行交換
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1] ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3] ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3] ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3] ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]byte, int, char, double, float, int, long ,short, Object 同理
toArray(T... items)?創建數組
String[] array = ArrayUtils.toArray("1", "2"); String[] emptyArray = ArrayUtils.<String>toArray();toMap(Object[] array)?將二維數組轉換成Map并返會Map
Map colorMap = ArrayUtils.toMap(new String[][] {{"RED", "#FF0000"},{"GREEN", "#00FF00"},{"BLUE", "#0000FF"}} );toObject(boolean[] array)?將基本類型數組轉換成對象類型數組并返回
byte, int, char, double, float, int, long ,short 同理
toPrimitive(Boolean[] array)?將對象類型數組轉換成基本類型數組并返回
byte, int, char, double, float, int, long ,short 同理
toString(Object array)?將數組轉換為string字符串并返回
toStringArray(Object[] array)?將Object數組轉換為String數組類型
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的commons-lang3工具类学习(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 缓存之EHCache(二)
- 下一篇: commons-lang3工具类学习(二