{"id":32489,"date":"2024-11-01T09:09:25","date_gmt":"2024-11-01T09:09:25","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32489"},"modified":"2024-11-01T11:55:05","modified_gmt":"2024-11-01T11:55:05","slug":"flutter-course-13-2-collection-types","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32489\/","title":{"rendered":"Flutter Course: 13.2 Collection Types"},"content":{"rendered":"<p>Hello! In this article, we will take a deep dive into a key component of Flutter, which is the collection types. Flutter is not only a powerful UI toolkit but is also based on the Dart language. In Dart, collection types play a very important role in managing data structures. They help efficiently process and manage various types of data.<\/p>\n<h2>Basic Concepts of Collection Types<\/h2>\n<p>Collection types are fundamentally ways to group and process data. Dart primarily offers three collection types: List, Set, and Map.<\/p>\n<ul>\n<li><strong>List<\/strong>: A set of ordered data. It allows duplicate values and accesses data using an index.<\/li>\n<li><strong>Set<\/strong>: A set of data that does not allow duplicates. It is very useful for adding, removing, and searching.<\/li>\n<li><strong>Map<\/strong>: A set of data composed of key-value pairs. Each key is unique, and values are accessed through these keys.<\/li>\n<\/ul>\n<h2>1. List<\/h2>\n<p>A List is a collection type that allows storing multiple data while maintaining the order of data. A List can be declared as follows:<\/p>\n<pre>\n<code>List<int> numbers = [1, 2, 3, 4, 5];<\/int><\/code>\n<\/pre>\n<p>In the example above, we created a List of type <code>int<\/code>. Lists provide various methods to handle data. For example:<\/p>\n<ul>\n<li><code>add(item)<\/code>: Adds a new item at the end of the list.<\/li>\n<li><code>remove(item)<\/code>: Removes a specific item from the list.<\/li>\n<li><code>contains(item)<\/code>: Checks if a specific item is included in the list.<\/li>\n<\/ul>\n<p>To gain a deeper understanding of Lists, let&#8217;s look at the example below:<\/p>\n<pre>\n<code>\nvoid main() {\n    List<string> fruits = [\"apple\", \"banana\", \"cherry\"];\n    \n    \/\/ Add item\n    fruits.add(\"orange\");\n    \n    \/\/ Remove item\n    fruits.remove(\"banana\");\n\n    \/\/ Print list contents\n    print(fruits); \/\/ Output: [apple, cherry, orange]\n    \n    \/\/ Check if specific item is included\n    if (fruits.contains(\"cherry\")) {\n        print(\"Cherry is in the list.\");\n    }\n}\n<\/string><\/code>\n<\/pre>\n<h3>1.1 Iterating through a List<\/h3>\n<p>To access each item in a List, you can use a loop:<\/p>\n<pre>\n<code>\nfor (var fruit in fruits) {\n    print(fruit);\n}\n<\/code>\n<\/pre>\n<p>Alternatively, you can access items directly using an index:<\/p>\n<pre>\n<code>\nfor (int i = 0; i &lt; fruits.length; i++) {\n    print(fruits[i]);\n}\n<\/code>\n<\/pre>\n<h2>2. Set<\/h2>\n<p>A Set is a collection that does not allow duplicates. If you try to store duplicate values, they will be ignored. A Set can be declared as follows:<\/p>\n<pre>\n<code>Set<string> colors = {\"red\", \"blue\", \"green\"};<\/string><\/code>\n<\/pre>\n<p>You can also use various methods in a Set:<\/p>\n<ul>\n<li><code>add(item)<\/code>: Adds an item to the Set. If it is a duplicate, it will be ignored.<\/li>\n<li><code>remove(item)<\/code>: Removes a specific item from the Set.<\/li>\n<li><code>contains(item)<\/code>: Checks if a specific item is included in the Set.<\/li>\n<\/ul>\n<p>Here is an example of using a Set:<\/p>\n<pre>\n<code>\nvoid main() {\n    Set<string> animals = {\"cat\", \"dog\", \"bird\"};\n    \n    \/\/ Add item\n    animals.add(\"rabbit\");\n    \n    \/\/ Add duplicate item (ignored)\n    animals.add(\"cat\");\n\n    \/\/ Print Set contents\n    print(animals); \/\/ Output: {cat, dog, bird, rabbit}\n    \n    \/\/ Check if specific item is included\n    if (animals.contains(\"dog\")) {\n        print(\"The dog is in the Set.\");\n    }\n}\n<\/string><\/code>\n<\/pre>\n<h2>3. Map<\/h2>\n<p>A Map is a collection that stores data in key-value pairs. The key acts as a unique identifier for each value. A Map can be declared as follows:<\/p>\n<pre>\n<code>Map<string, int=\"\"> studentGrades = {\"John\": 85, \"Kim\": 90};<\/string,><\/code>\n<\/pre>\n<p>A Map also provides several methods to manage data:<\/p>\n<ul>\n<li><code>put(key, value)<\/code>: Adds a new key-value pair to the Map.<\/li>\n<li><code>remove(key)<\/code>: Removes the item associated with a specific key.<\/li>\n<li><code>containsKey(key)<\/code>: Checks if a specific key is included in the Map.<\/li>\n<\/ul>\n<h3>3.1 Example of Using a Map<\/h3>\n<p>Here is a simple example of using a Map:<\/p>\n<pre>\n<code>\nvoid main() {\n    Map<string, int=\"\"> studentGrades = {\"John\": 85, \"Kim\": 90};\n    \n    \/\/ Add new student\n    studentGrades[\"Lee\"] = 95;\n    \n    \/\/ Print specific student's grades\n    print(\"Lee's grades: ${studentGrades[\"Lee\"]}\");\n    \n    \/\/ Print all students and their grades\n    studentGrades.forEach((name, grade) {\n        print(\"$name: $grade\");\n    });\n}\n<\/string,><\/code>\n<\/pre>\n<h2>Utilizing Collection Types<\/h2>\n<p>Let&#8217;s look at a practical example of utilizing collection types. This will help us understand how to use data structures in real development situations.<\/p>\n<h3>Example: Storing User Information<\/h3>\n<p>Assuming we are developing an application to store user information. In this case, we can utilize Lists and Maps:<\/p>\n<pre>\n<code>\nclass User {\n    String name;\n    int age;\n\n    User(this.name, this.age);\n}\n\nvoid main() {\n    List<user> users = [];\n    \n    \/\/ Add users\n    users.add(User(\"John\", 25));\n    users.add(User(\"Kim\", 30));\n\n    \/\/ Print user information\n    for (var user in users) {\n        print(\"Name: ${user.name}, Age: ${user.age}\");\n    }\n    \n    \/\/ Create Map with user names as keys\n    Map<string, user=\"\"> userMap = {for (var user in users) user.name: user};\n\n    \/\/ Search for a user\n    String searchName = \"John\";\n    if (userMap.containsKey(searchName)) {\n        User foundUser = userMap[searchName]!;\n        print(\"${foundUser.name}'s age is ${foundUser.age}.\");\n    }\n}\n<\/string,><\/user><\/code>\n<\/pre>\n<h2>6. Conclusion<\/h2>\n<p>In this session, we took a close look at the collection types in Flutter, which can effectively manage data structures: List, Set, and Map. Each collection type has its distinct characteristics, and developers can choose the appropriate data depending on the situation. Through effective data management, developers can write more efficient and maintainable code.<\/p>\n<p>Additionally, one should also consider potential performance issues or memory management that may arise when using collection types. Keep these points in mind as you design your own appropriate data structures. We will strive to cover in-depth topics in the next session as well. Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this article, we will take a deep dive into a key component of Flutter, which is the collection types. Flutter is not only a powerful UI toolkit but is also based on the Dart language. In Dart, collection types play a very important role in managing data structures. They help efficiently process and &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32489\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Flutter Course: 13.2 Collection Types&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[151],"tags":[],"class_list":["post-32489","post","type-post","status-publish","format-standard","hentry","category-flutter-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flutter Course: 13.2 Collection Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32489\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flutter Course: 13.2 Collection Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this article, we will take a deep dive into a key component of Flutter, which is the collection types. Flutter is not only a powerful UI toolkit but is also based on the Dart language. In Dart, collection types play a very important role in managing data structures. They help efficiently process and &hellip; \ub354 \ubcf4\uae30 &quot;Flutter Course: 13.2 Collection Types&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32489\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:09:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:55:05+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32489\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32489\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Flutter Course: 13.2 Collection Types\",\"datePublished\":\"2024-11-01T09:09:25+00:00\",\"dateModified\":\"2024-11-01T11:55:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32489\/\"},\"wordCount\":562,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Flutter course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32489\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32489\/\",\"name\":\"Flutter Course: 13.2 Collection Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:09:25+00:00\",\"dateModified\":\"2024-11-01T11:55:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32489\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32489\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32489\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flutter Course: 13.2 Collection Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flutter Course: 13.2 Collection Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32489\/","og_locale":"ko_KR","og_type":"article","og_title":"Flutter Course: 13.2 Collection Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this article, we will take a deep dive into a key component of Flutter, which is the collection types. Flutter is not only a powerful UI toolkit but is also based on the Dart language. In Dart, collection types play a very important role in managing data structures. They help efficiently process and &hellip; \ub354 \ubcf4\uae30 \"Flutter Course: 13.2 Collection Types\"","og_url":"https:\/\/atmokpo.com\/w\/32489\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:09:25+00:00","article_modified_time":"2024-11-01T11:55:05+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32489\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32489\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Flutter Course: 13.2 Collection Types","datePublished":"2024-11-01T09:09:25+00:00","dateModified":"2024-11-01T11:55:05+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32489\/"},"wordCount":562,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Flutter course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32489\/","url":"https:\/\/atmokpo.com\/w\/32489\/","name":"Flutter Course: 13.2 Collection Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:09:25+00:00","dateModified":"2024-11-01T11:55:05+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32489\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32489\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32489\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Flutter Course: 13.2 Collection Types"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32489"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32489\/revisions"}],"predecessor-version":[{"id":32490,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32489\/revisions\/32490"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}