강의

멘토링

커뮤니티

Inflearn Community Q&A

pcs's profile image
pcs

asked

[Introductory] Kotlin Syntax for Android

Find scores 50+: Practice

for 문 밖에서의 list 타입의 차이점

Written on

·

245

0

// 조건문

// if else

// when

fun main() {

val testlist = mutableMapOf<String, Int>()

testlist["a"] = 10

testlist["b"] = 50

testlist["c"] = 60

testlist["d"] = 100

testlist["e"] = 70

testlist["f"] = 30

// 50점이상 구하기

println(testlist.keys::class.java.simpleName)

for (i in testlist){

println(i.key::class.java.simpleName)

}

 

}

 

 

위 코드처럼 작성 후 타입을 비교하였을 때 두가지의 타입이 다르게 나와있는데 그 이유를 모르겠습니다

kotlin코딩-테스트

Answer 2

0

pcs님의 프로필 이미지
pcs
Questioner

답변 감사합니다!

 

0

bokchi님의 프로필 이미지
bokchi
Instructor

testlist.keys는 말 그대로 list의 전체입니다.

반복문을 통해 i.key 개별적으로 나오는 것과 다른 것이 당연합니다.

 

데이터 덩어리.keys

덩어리의 한 부분.key

 

가 다르다고 생각해주시면 됩니다.

 

pcs's profile image
pcs

asked

Ask a question