[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-697916-105":59,"doc-detail-697916-en":130,"doc-similar-697916":162},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":123,"head_meta":125,"extra_data":127,"updated_unix":129},105,"en","java-collections-list-set-map","Java Collections - List Set Map","","Explains the core Java Collections Framework and how to use its three main collection types: List, Set, and Map. Describes List as a dynamically sized linear structure, Set as a collection that rejects duplicate elements, and Map as a key/value lookup dictionary. Covers the Collection hierarchy, typical implementations like ArrayList, LinkedList, HashSet, and HashMap, and demonstrates common operations including constructing lists, adding elements, copying collections, iterating with foreach and indexed loops, and accessing elements by index.",{"@graph":69,"@context":122},[70,84,105],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":30,"@type":76,"position":81},"https://docshare.wps.com/document/technology/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/java-collections-list-set-map/697916/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":99,"encodingFormat":97,"isAccessibleForFree":100,"interactionStatistic":101},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/java-collections-list-set-map/697916.png","ImageObject",300,407,{"name":92,"@type":93},"sagouaw","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-27","2026-11-12",true,{"@type":102,"interactionType":103,"userInteractionCount":29},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"What are the three most important Java collection types and what does each do?","Question",{"text":112,"@type":113},"List stores elements in an ordered sequence that grows and shrinks automatically. Set rejects duplicate elements automatically. Map stores data as key/value pairs for efficient lookup by key.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"How do you create a List of Strings in Java using ArrayList and generics?",{"text":117,"@type":113},"Declare the variable as List\u003CString> and instantiate it with new ArrayList\u003CString>(), e.g., List\u003CString> words = new ArrayList\u003CString>();.",{"name":119,"@type":110,"acceptedAnswer":120},"What iteration approaches are shown for lists, and what restriction applies to foreach?",{"text":121,"@type":113},"The document shows an enhanced foreach loop and a traditional index-based for loop. It states it is not valid to add or remove elements from a list while a foreach loop is iterating over that list.","https://schema.org",{"og:url":83,"og:type":124,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":126,"canonical":83},"index,follow",{"doc_id":128,"site_id":62},697916,1794445817,{"code":4,"msg":5,"data":131},{"doc_id":128,"user_id":132,"nickname":92,"user_avatar":133,"doc_module":4,"category_id":29,"category_name":30,"doc_title":65,"doc_description":67,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":29,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":139,"language":140,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":67,"update_tm":129,"read_time":144,"preview_page_count":19,"preview_urls":145},3985747862151,"https://ap-avatar.wpscdn.com/davatar_a8503ba1806abce46bf441b54a3ca4cd","Java Collections--List Set Map  \nCopyright 2006-07, by Nick Parlante,([nick.parlante@cs.stanford.edu](nick.parlante@cs.stanford.edu)). The Java \"Collection\" classes make it easy to store and manipulate collections of information. You should be familiar with the collection classes so you can leverage their many built-in features in your own code.  \nThis document introduces the main features of the java collections framework. The three most important types are \"List\", \"Set\", and \"Map\". A List is like an array, except it grows and shrinks automatically as needed. The Set is like the List, but automatically rejects duplicate elements. The Map is a key/value dictionary that supports the efficient storage and retrieval of information by a key. There are official Sun docs for the collections framework at  \n[http://java.sun.com/javase/6/docs/technotes/guides/collections/index.html](http://java.sun.com/javase/6/docs/technotes/guides/collections/index.html)  \nThe Collection interface is a general interface that includes sub-interfaces List and Set. If a method has a parameter of type Collection, such as the addAll(Collection coll) method below, you can pass it a List or Set and it will work fine. List is an interface, and ArrayList is the typically used class that implements List. Likewise, Set is an interface, and HashSet is the commonly used class that implements Set. The Map interface is separate from the Collection interface. The Map interface defines a key/value lookup dictionary, and HashMap is the most commonly used Map. The sections below explain all of these classes.  \nLists  \nThe List is probably the single most useful and widely used type of Collection. List is a general interface, and ArrayList and LinkedList are implementing classes. ArrayList is the best general purpose List, so that's what we'll use here.  \nA List is a linear structure where each element is known by an index number 0, 1, 2, ... len-1 (like an array). Lists can only store objects, like String and Integer, but not primitives like int. You cannot create a List of int, but you can create a list of Integer objects. This is a common feature of all the Java Collection classes (see boxing below). Another way to say this is that the collection classes can only store pointers.  \nBasic List  \nHere is code to create a new list to contain Strings:  \nList\u003CString> words = new ArrayList\u003CString>();  \nThe \"words\" variable is declared to be type \"List\u003CString>\" -- \"List\" being the general interface for all lists, and the \"\u003CString>\" is the generic syntax means this is a list that contains String elements. (Before Java 5, Collections did not have the \u003CString> generic notations, but otherwise worked pretty much the same as shown here.) On the right hand side the \"new AarrayList\u003CString>()\" creates a new ArrayList of Strings, also using the \"List\u003CString>\" syntax. The ArrayList class implements the List interface, which is how we can store a pointer to an ArrayList in a List variable. Using the general List type for the variable as shown here is the standard way to store an ArrayList--that way you can substitute a LinkedList or whatever later if needed.  \nList add()  \nA new ArrayList is empty. The add() method adds a single element to the end of the list, like this:  \nwords .add(\"this\");  \nwords .add(\"and\");  \nwords .add(\"that\");  \n// words is now: {\"this\", \"and\", \"that\"} words.size() // returns 3  \nThe size() method returns the int size of a list (or any collection).  \nFor all the collection classes, creating a new one with the default constructor gives you an empty collection. However, you can also call the constructor passing an existing collection argument, and this creates a new collection that is a copy. So we could copy the elements from words into a second list like this:  \n// Create words2 which is a copy of words  \nList\u003CString> words2 = new ArrayList\u003CString>(words);  \nNote: this just copies the elements (pointers) that are in \"words\" into \"words2\" --it just does an = for","cbCaipOG7J4dr1VN","https://ap.wps.com/l/cbCaipOG7J4dr1VN","pdf",110915,11,"English","# Java Collections Framework Overview\n## Key Types: List, Set, Map\n# List Fundamentals\n## Creating and Typing Lists with Generics\n## Adding Elements and Checking Size\n## Copying Collections\n## Iterating Over Lists\n## Accessing Elements by Index","[{\"question\":\"What are the three most important Java collection types and what does each do?\",\"answer\":\"List stores elements in an ordered sequence that grows and shrinks automatically. Set rejects duplicate elements automatically. Map stores data as key/value pairs for efficient lookup by key.\"},{\"question\":\"How do you create a List of Strings in Java using ArrayList and generics?\",\"answer\":\"Declare the variable as List\\u003cString\\u003e and instantiate it with new ArrayList\\u003cString\\u003e(), e.g., List\\u003cString\\u003e words = new ArrayList\\u003cString\\u003e();.\"},{\"question\":\"What iteration approaches are shown for lists, and what restriction applies to foreach?\",\"answer\":\"The document shows an enhanced foreach loop and a traditional index-based for loop. It states it is not valid to add or remove elements from a list while a foreach loop is iterating over that list.\"}]","Java Collections - List Set Map | PDF",28,[146,150,154,158],{"page_no":8,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/56cc1396c3e0bdef48c645cc9665005c.webp",983,1272,{"page_no":14,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/ad4ff502a5cded838c24f3156bdaae2b.webp",982,1270,{"page_no":81,"url":155,"width":156,"height":157},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/e1f921e6d135501612229eaedbe47d5d.webp",981,1269,{"page_no":19,"url":159,"width":160,"height":161},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-12/33caf45ae6b37e59cc0c5683abc7a0af.webp",980,1268,{"list":163,"token":66},[164,170,176,182,188,194,200,206,212,218],{"doc_id":165,"doc_title":166,"file_type":137,"home_preview_img_url":167,"slug":168,"view_count":19,"category_name":30,"create_tm":169},685691,"ArrayList and Iterator in Java - Java List Iteration Methods and Examples","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179348/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=vznV8dF7GIO49vNPRbfMcAv48qI%3D","arraylist-and-iterator-in-java-java-list-iteration-methods-and-examples",1794016767,{"doc_id":171,"doc_title":172,"file_type":137,"home_preview_img_url":173,"slug":174,"view_count":19,"category_name":30,"create_tm":175},685658,"Lesson 4 - Collections and iterators","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000173197/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=InieR%2Fdsg2qyK%2Fgr%2BevifoHuC%2Bg%3D","lesson-4-collections-and-iterators",1794016351,{"doc_id":177,"doc_title":178,"file_type":137,"home_preview_img_url":179,"slug":180,"view_count":19,"category_name":30,"create_tm":181},685692,"ArrayList vs LinkedList - For Introduction to Java Programming - Performance Comparison","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179353/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=6LB3PeX8uR0DEmu%2BeQu3ugKCuKo%3D","arraylist-vs-linkedlist-for-introduction-to-java-programming-performance-comparison",1794016770,{"doc_id":183,"doc_title":184,"file_type":137,"home_preview_img_url":185,"slug":186,"view_count":34,"category_name":30,"create_tm":187},685695,"High Performance Lists in Java - JavaZone 2015 - Motivation: A Real World Example","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179383/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=qlB%2FjzI1Oq6b8ne2o9N9MMECwJE%3D","high-performance-lists-in-java-javazone-2015-motivation-a-real-world-example",1794016775,{"doc_id":189,"doc_title":190,"file_type":137,"home_preview_img_url":191,"slug":192,"view_count":24,"category_name":30,"create_tm":193},685686,"ArrayList in Java","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179246/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=bLcnzAakA3LtXyJkODqXaYibqvo%3D","arraylist-in-java",1794016760,{"doc_id":195,"doc_title":196,"file_type":137,"home_preview_img_url":197,"slug":198,"view_count":19,"category_name":30,"create_tm":199},719603,"CS1020 Data Structures and Algorithms I Lecture 10 - List ADT & Linked Lists","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023815866/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=kFnVp3sB4lP0i%2FvcyGc4cDO6GHg%3D","cs1020-data-structures-and-algorithms-i-lecture-10-list-adt-linked-lists",1795006746,{"doc_id":201,"doc_title":202,"file_type":137,"home_preview_img_url":203,"slug":204,"view_count":24,"category_name":30,"create_tm":205},697921,"Java Collections Framework - Interfaces, Implementations, and Core Algorithms","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010131024/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=f4G%2BFVhFGMSyxviYxEvXTo0N65A%3D","java-collections-framework-interfaces-implementations-and-core-algorithms",1794445828,{"doc_id":207,"doc_title":208,"file_type":137,"home_preview_img_url":209,"slug":210,"view_count":29,"category_name":30,"create_tm":211},685634,"Python Collections - Arrays - List and Function","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999084045/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=JXgVTyys7oumtBR66U%2BdB0%2FBF%2BI%3D","python-collections-arrays-list-and-function",1794016101,{"doc_id":213,"doc_title":214,"file_type":137,"home_preview_img_url":215,"slug":216,"view_count":81,"category_name":30,"create_tm":217},671829,"For Loop Chess Board - Make it print a chess board","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229988408535/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=7RVzelZTemU%2Ffm41g5x9Z4fDPwk%3D","for-loop-chess-board-make-it-print-a-chess-board",1793581238,{"doc_id":219,"doc_title":220,"file_type":137,"home_preview_img_url":221,"slug":222,"view_count":19,"category_name":30,"create_tm":223},685687,"ArrayList - Short Version","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179262/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=mDoFXfP6oqUZVtuv18Vxz7li7z0%3D","arraylist-short-version",1794016761]