Java Arrays 클래스
Arrays로 배열 다루기
문자열 비교와 출력
int[] arr = {0, 1, 2, 3, 4};
int[][] arr2D = {{11, 22}, {33, 44}};
System.out.println(Arrays.toString(arr));
System.out.println(Arrays.deepToString(arr2D));
int[][] int2D = {{11, 22}, {33, 44}};
int[][] int2D2 = {{10, 20}, {30, 40}};
System.out.println(Arrays.equals(arr2D, int2D));
System.out.println(Arrays.deepEquals(arr2D, int2D));
System.out.println(Arrays.deepEquals(arr2D, int2D2));
배열의 복사
import java.util.Arrays;
public class EX5_9 {
public static void main(String[] args) {
int[] arr = {0, 1, 2, 3, 4};
int[] arr2 = Arrays.copyOf(arr, arr.length);
int[] arr3 = Arrays.copyOf(arr, 3);
int[] arr4 = Arrays.copyOf(arr, 7);
int[] arr5 = Arrays.copyOfRange(arr, 2, 4);
int[] arr6 = Arrays.copyOfRange(arr, 0, 7);
System.out.println(Arrays.toString(arr));
System.out.println(Arrays.toString(arr2));
System.out.println(Arrays.toString(arr3));
System.out.println(Arrays.toString(arr4));
System.out.println(Arrays.toString(arr5));
System.out.println(Arrays.toString(arr6));
}
}
배열의 정렬(오름차순 정렬)
import java.util.Arrays;
public class EX5_10 {
public static void main(String[] args) {
int[] arr = {3, 1, 2, 4, 0};
System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
}