JAVA/23. Arrays
Arrays 정리
날아올라↗↗
2015. 12. 1. 21:47
728x90
반응형
- package test.com;
- import java.util.Arrays;
- public class Test01Arrays {
- public static void main(String[] args) {
- System.out.println("Arrays...");
- int[] temps = new int[]{22,33,44,11,34,41};
- //순정렬
- //11,22,33,34,41,44
- Arrays.sort(temps);
- for (int i : temps) {
- System.out.println(i);
- }
- //데이터 index검색(정렬이후에 사용)
- System.out.println(Arrays.binarySearch(temps, 33));
- //배열비교
- boolean bool = Arrays.equals(temps, new int[]{22,33,44,11,34,41});
- System.out.println(bool);
- //배열데이터 전부 채우기, 변경
- Arrays.fill(temps, 99);
- //배열데이터 부분 채우기, 변경
- Arrays.fill(temps, 2, 4, 18);
- for (int i : temps) {
- System.out.println(i);
- }
- }
- }
==================================================
배열정리
[코드설명]
10. 임의의 int형 배열변수를 선언
14. Arrays 클래스의 sort 메소드를 통해 순정렬로 정리
16~18. for each구문으로 해당 배열값 출력
21. 해당 배열요소가 어느위치에 있는지 출력 - 데이터 인덱스 검색의 경우 정렬이후에 사용
24. boolean 타입으로 두 배열의 값이 동일한지 체크. 동일하면 true, 다를경우 false
28~34. Arrays.fill 메소드를 통해 배열값 전체 변경 및 특정위치 배열 값 변경 가능
728x90
반응형