java.util.Arrays 类是 Java 标准库中用于操作数组的实用工具类。它提供了多种静态方法,用于对数组进行排序、搜索、比较、填充、转换等操作。
package com.sut.hello.cm;
import java.util.Arrays;
import java.util.function.IntToDoubleFunction;
public class test {
public static void main(String[] args) {
int[] a = {4,2,6,8,3};
System.out.println(Arrays.toString(a));//[4, 2, 6, 8, 3]
int[] b = Arrays.copyOfRange(a,1,3);
System.out.println(Arrays.toString(b));//[2, 6]
int[] d = Arrays.copyOf(a,10);
System.out.println(Arrays.toString(d));//[4, 2, 6, 8, 3, 0, 0, 0, 0, 0]
double[] c = {1.1,3.6,4.5};
Arrays.setAll(c, new IntToDoubleFunction(){
public double applyAsDouble(int i)
{
return c[i]*5;
}
});
System.out.println(Arrays.toString(c));//[5.5, 18.0, 22.5]
Arrays.sort(a);
System.out.println(Arrays.toString(a));//[2, 3, 4, 6, 8],默认升序
}
}