zoukankan      html  css  js  c++  java
  • 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"]) = 3

    hashCode(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)    = null

    byte, 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数组类型
    ---------------------
    作者:allsmallpig
    来源:CSDN
    原文:https://blog.csdn.net/u012240455/article/details/79014161
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    函数
    A × B problem
    求n的阶乘
    自己构建一个vector函数
    int与string的互相转化
    列一列(斐波那契数列)
    找一找
    c++大数计算模板
    JSON--js中 json字符串转对象、对象转字符串
    JSON
  • 原文地址:https://www.cnblogs.com/xinglongbing521/p/10384081.html
Copyright © 2011-2022 走看看