Kotlin - 배열 요소로 접근하여 사용

CODEDRAGON Development/Kotlin

반응형


 

 

배열 요소로 접근하여 사용

 

배열명과 인덱스를 통해 요소에 접근합니다.

배열명[인덱스]

 

 

for( i in array.indices){

println("array[${i}]: ${array.get(i)}")

}

 

 

for반복문과 배열의 withIndex()함수를 통해 index 요소를 순차적으로 순회하면서 반복문을 수행합니다.

for( (index, element) in rangeObj.withIndex() ){

println("array[${index}]: ${element}")

}

 

 


반응형