일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- string
- date
- 배열
- Java
- 자바
- 이클립스
- Maven
- IntelliJ
- 정규식
- CMD
- list
- Array
- js
- 인텔리제이
- CSS
- ArrayList
- vscode
- 테이블
- input
- 이탈리아
- 자바스크립트
- windows
- Visual Studio Code
- javascript
- Eclipse
- Button
- 문자열
- table
- json
- html
- Today
- Total
목록인덱스 (3)
어제 오늘 내일
Java에서 특정 인덱스를 기준으로 배열을 자르는 2가지 방법을 소개합니다. 반복문 이용하기 Arrays.copyOfRange() 이용하기 1. 반복문 이용하기 import java.util.Arrays; public class ArraySplit { public static void main(String[] args) { // 1. 원본 배열 int[] arr = {0, 1, 2, 3, 4, 5}; // 2. 배열을 자를 index int position = 3; // 3. 자른 배열을 담을 새로운 배열 int[] arr1 = new int[position]; int[] arr2 = new int[arr.length - position]; // 4. 배열 자르기 for(int i = 0; i < arr..

ArrayList의 첫번째 index는 "0"이고, 마지막 index는 "ArrayList의 길이 - 1" 입니다. 위와 같은 ArrayList가 있고, 이 ArrayList에 5개의 element가 있을 때, ArrayList의 index는 0부터 시작하기 때문에, 첫번째 index는 "0"이고, 마지막 index는 "ArrayList의 길이 - 1"입니다. 코드 import java.util.ArrayList; import java.util.List; public class ArrayListFirstLastIndex { public static void main(String[] args) { // ArrayList 준비 List arrayList = new ArrayList(); arrayList.a..
지난번에는 배열의 여러 원소들 중 최대값과 최소값을 구하는 방법을 알아보았습니다. [Java] 배열 원소 중 최대값, 최소값 구하기 이번에는 최대값과 최소값을 가지는 배열의 인덱스(index) 값을 구하는 방법을 알아보도록 하겠습니다. 최대값 / 최대값 인덱스 구하기 코드 public class Max { public static void main(String[] args) { int[] arr = { 3, 2, 1, 5, 4 }; // 최대값, 최대값의 인덱스 초기값 세팅 int max = arr[0]; int maxIndex = 0; // 최대값, 최대값의 인덱스 구하기 for (int i = 0; i max) { max = arr[i]; ..