@Test
public void test6() {
int[] arr = {56, 34, 78, 2, 0, 18};
//给数组元素排序
Arrays.sort(arr); //排序方法,顺序(从小到大)
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]+",");
}
System.out.println("最大值:"+arr[arr.length-1]);
}
String s = Arrays.toString(arr); //将数组转换成字符串
System.out.println(s);
@Test
public void test11() {
int[] arr = {};
// arr = expendMemory(arr, 1);
// arr = expendMemory(arr, 2);
// arr = expendMemory(arr, 3);
// arr = expendMemory(arr, 4);
// System.out.println(Arrays.toString(arr));
System.out.println(arr.length);
arr = Arrays.copyOf(arr, arr.length+1);
System.out.println(arr.length);
private int[] expendMemory(int[] arr, int value) {
if(arr == null) {
arr = new int[]{};
}
int[] a = new int[arr.length+1];
a[a.length-1] = value;
for(int i=0; i<arr.length; i++) {
a[i] = arr[i];
}
return a;
}
}