본문 바로가기

개발일지714

dart - Map을 Mapping할때 - (다트 - 맵을 매핑할때) void main(){ Map harryPotter = { 'Harry Potter': '해리 포터', 'Ron Weasley' : '론 위즐리', 'Hermione Granger': '헤르미온느 그레인저' }; // map을 mapping 할때는 key와 value가 필요하다. final result = harryPotter.map( (key,value)=> MapEntry( 'Harry Potter Character $key', '해리포터 캐릭터 $value' ), ); print(result); // {Harry Potter Character Harry Potter: 해리포터 캐릭터 해리 포터, // Harry Potter Char.. 2025. 3. 24.
dart - List를 Mapping // List를 mappingvoid main() { List blackPink = ['로제', '지수', '리사', '제니']; // 첫번째 형변환 map으로 출력 값 달리해주는 방법 final newBlackPink = blackPink.map((x){ // return 에 쓰일 값이 파라미터의 x를 대체해줄 것 return '블랙핑크 $x'; }); // 두번째 형변환 map으로 출력 값 달리해주는 방법 final newBlackPink2 = blackPink.map((x) => '블랙핑크 $x'); print(blackPink); // [로제, 지수, 리사, 제니] print(newBlackPink); // (블랙핑크 로제, 블랙핑크 지수, 블랙핑크 .. 2025. 3. 24.
dart - 형변환 리스트-맵-셋 (List - Map - Set) void main(){ List blackPink = ['로제', '지수', '제니', '리사', '제니']; print(blackPink); // [로제, 지수, 제니, 리사, 제니] // dictionaly 화 해주는 asMap print(blackPink.asMap()); // {0: 로제, 1: 지수, 2: 제니, 3: 리사, 4: 제니} // set은 중복 제거 + {}안에 가둬두기 print(blackPink.toSet()); // {로제, 지수, 제니, 리사} Map blackPinkMap = blackPink.asMap(); print(blackPinkMap.keys); // (0, 1, 2, 3, 4) print(blackPinkMap.values.. 2025. 3. 24.
dart - class generic 다트 - 클래스 제네릭 6 void main() { // 여기서 안에 들어간 String도 generic이다. List names = []; Lecture lecture1 = Lecture('123', 'lecture1'); lecture1.printIdType(); Lecture lecture2 = Lecture(123, 'lecture2'); lecture2.printIdType(); }// generic - 타입을 외부에서 받을때 사용// 그냥 안에 뭐라도 넣어주면 된다.// Lecture옆에 안에 T,A이런식으로 들어가게 되면, 타입이 2개 들어가게 되고,// 파라미터에 값이 들어가는 첫번째 타입이 T에 지정되고, 두번째 타입이 A에 들어가게 된다.class Lecture { final int .. 2025. 3. 24.