1. Arrays.sort() ; Arrays.toString()
import java.util.Arrays;
public class Test11 {
public static void main(String[] args) {
int[] arr=new int[] {1,0,9,8,4,5,6};
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
}
2. Arrays.copyOf()
import java.util.Arrays;
public class Test11 {
public static void main(String[] args) {
int[] ic = { 0, 1, 2, 3, 4 };
int[] id = Arrays.copyOf(ic, ic.length);// 若第二个参数大于ic的元素个数,则相应的元素初值为0
System.out.println(Arrays.toString(id));
}
}
3. System.arraycopy(from , fromIndex , to , toIndex , count )
import java.util.Arrays;
public class Test11 {
public static void main(String[] args) {
int[] ia = { 0, 1, 2, 3, 4 };
int[] ib = { 100, 101, 102, 103, 104, 105 };
System.arraycopy(ib,4,ia,2,2);//不是插入,是替换,不能越界复制
System.out.println(Arrays.toString(ia));
}
}
4. Arrays.deepToString()
import java.util.Arrays;
public class Test11 {
public static void main(String[] args) {
//交换二维数组两行
int [ ][ ] a={{1,2},{2,3},{3,4,5}};
int [] temp=a[0];
a[0]=a[1];
a[1]=temp;
System.out.println(Arrays.deepToString(a));
}
}