[플러터] List, Map

쿼티·2024년 4월 2일

플러터

목록 보기
2/33

void main() {
List blackpink =['제니', '지수', '로제', '리사'];
print(blackpink.length);
blackpink.add('코드팩토리');
blackpink.remove('제니');
print(blackpink.indexOf('로제'));
}

void main() {
//Map -> Key, Value
Map<String, String> dictionary ={
'Harry Potter':'해리포터',
'Ron':'론',
'Hermione':'헤르미온느'
};
print(dictionary);
Map<String, bool> isHarryPotter={
'Harry Potter': true,
'Ron': false,
'Hermione': false
};
print(isHarryPotter);
isHarryPotter.addAll({
'Spiderman':false,
'Ironman': false
});
print(isHarryPotter);
print(isHarryPotter['Ironman']);
//value 값만 가지고 올 수 있음. (key 값은 가지고 올 수 없다.)
}

{Harry Potter: 해리포터, Ron: 론, Hermione: 헤르미온느}
{Harry Potter: true, Ron: false, Hermione: false}
{Harry Potter: true, Ron: false, Hermione: false, Spiderman: false, Ironman: false}
false

void main() {
Map<String, bool> isHarryPotter={
'Harry Potter': true,
'Ron': false,
'Hermione': false,
'Spiderman':false,
'Ironman': false
};
print(isHarryPotter);
isHarryPotter.remove('Harry Potter');
print(isHarryPotter);
//키와 값 모두가 제거된다.
print(isHarryPotter.keys);
print(isHarryPotter.values);
}

{Harry Potter: true, Ron: false, Hermione: false, Spiderman: false, Ironman: false}
{Ron: false, Hermione: false, Spiderman: false, Ironman: false}
(Ron, Hermione, Spiderman, Ironman)
(false, false, false, false)

//map 설명 by chatGPT

플러터(Flutter)에서의 맵(Map)은 키(key)와 값(value)의 쌍으로 구성된 컬렉션입니다. 이 맵은 다음과 같은 특징을 가지고 있습니다:

키와 값의 연결: 맵은 각각의 키와 그에 상응하는 값으로 구성되어 있습니다. 이는 키를 사용하여 값을 검색하거나 수정할 수 있음을 의미합니다.

순서가 없음: 맵은 순서가 없는 데이터 구조입니다. 즉, 맵에 추가된 순서대로 요소가 저장되지 않습니다. 따라서 맵의 요소에 접근할 때 키를 사용하여 특정 요소를 검색해야 합니다.

고유한 키: 맵은 고유한 키를 가져야 합니다. 즉, 동일한 키가 두 번 이상 나타날 수 없습니다. 하지만 값은 중복될 수 있습니다.

플러터에서 맵은 Map 클래스를 사용하여 생성됩니다. 예를 들어, 다음과 같이 맵을 생성하고 사용할 수 있습니다:

업로드중..

profile
아무거나 만들자

0개의 댓글