import java.util.Arrays;
public class Demo09 {
public static void main(String[] args) {
System.out.println("==============Arrays.sort()===============");
int[] b = {1, 5, 9, 2, 7, 5};
Arrays.sort(b);
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + " ");
}
System.out.println();
System.out.println("==============Arrays.fill(int[] a, int val)===============");
int[] c = {1, 5, 9, 2, 7, 5};
Arrays.fill(c, 2);
for (int i = 0; i < c.length; i++) {
System.out.print(c[i] + " ");
}
System.out.println();
System.out.println("==============Arrays.fill(int[] a, int fromIndex, int toIndex, int val)=============");
int[] d = {1, 5, 9, 6, 7, 5};
Arrays.fill(d, 2, 4, 2);
for (int i = 0; i < d.length; i++) {
System.out.print(d[i] + " ");
}
}
}
运行结果
==============Arrays.sort()===============
1 2 5 5 7 9
==============Arrays.fill(int[] a, int val)===============
2 2 2 2 2 2
==============Arrays.fill(int[] a, int fromIndex, int toIndex, int val)=============
1 5 2 2 7 5
Process finished with exit code 0
Arrays工具类的使用