[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-685796-105":59,"doc-detail-685796-en":130,"doc-similar-685796":149},{"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","arraylists-introduction-to-java-arraylist-and-generics","ArrayLists - Introduction to Java ArrayList and Generics","","ArrayLists explains how Java’s ArrayList provides a dynamic array that can grow or shrink during program execution, overcoming the fixed-size limitation of standard arrays. It introduces generics to create lists of arbitrary data types, discusses why arrays may be preferable in some cases, and shows the object-only requirement using Integer wrappers. The document then details core ArrayList operations, including add, insert, set, get, remove, indexOf, and size, with example code and usage patterns.",{"@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/arraylists-introduction-to-java-arraylist-and-generics/685796/",{"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/arraylists-introduction-to-java-arraylist-and-generics/685796.png","ImageObject",300,407,{"name":92,"@type":93},"Stanley","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-18","2026-11-07",true,{"@type":102,"interactionType":103,"userInteractionCount":81},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"What makes Java ArrayList different from regular arrays?","Question",{"text":112,"@type":113},"ArrayList acts like a dynamic array that can grow or shrink in size at runtime, unlike regular arrays which require a fixed size after declaration.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"Why can ArrayList elements be objects but not primitive types directly?",{"text":117,"@type":113},"ArrayList stores objects, so primitive types like int must be wrapped (e.g., using Integer) or represented via custom object classes.",{"name":119,"@type":110,"acceptedAnswer":120},"How do you add, insert, and update elements in an ArrayList?",{"text":121,"@type":113},"Use add(newElement) to append, add(index, newElement) to insert at a position, and set(index, newElement) to replace an existing element at that index.","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},685796,1794018675,{"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":81,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":34,"language":139,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":67,"update_tm":129,"read_time":143,"preview_page_count":8,"preview_urls":144},2336477405376,"https://ap-avatar.wpscdn.com/davatar_29158cc5080c5b710cf443261637dec0","ArrayLists, Generics  \nA data structure is a software construct used to organize our data in a particular way. Some common data structures include lists, stacks, queues, and heaps. Dynamic data structures are those data structures that can grow as needed while a program is running. First we will look at a useful class provided by Java called an ArrayList. This class uses a feature called generics to allow us to create lists of arbitrary data types. Then we will see how to create our own data structures, in particular, how to create dynamically linked lists.  \nArrayLists  \nThe ArrayList class provided by Java is essentially a way to create an array that can grow or shrink in size during the execution of a program. If you recall the section on arrays, once we declared an array to be a particular size we were not able to change that size. For example, in our trivia game we declared the array to be of size 5. This means we have a maximum of 5 questions and can never exceed that amount. This is because Java allocates a specific amount of memory to hold exactly the number of items we initially specified. We could get around that problem by creating a new array of the size we like and copy the elements we want into it, but this approach is time consuming. The arraylist class does the dirty work for us to give us the same effect as a dynamic array.  \nIf arraylists do the same thing as arrays but are dynamic, why not use them all the time? We could (and some people do) but there are two good reasons to use arrays over arraylists:  \n1. Arrays are more efficient than arraylists  \n2. The elements in an arraylist must be objects (which contributes to \\#1 for simple items)  \n3. We can’t use the convenient [] notation on arraylists  \nIf we wanted an arraylist of int’s, then we instead we would have to make an arraylist of class Integer, which is a wrapper class for objects of type int (or we could make our own class) .  \nHere is how we use an arraylist. To access the arraylist code we can import the class via:  \nimport java.util.ArrayList;  \nTo create a variable of type ArrayList that is a list of type DataType use the following:  \nArrayList\u003CDataType> varName = new ArrayList\u003CDataType> ();  \nIf you know how many items the arraylist will likely need, execution can be a bit faster by specifying an initial capacity. Note however that we can still change the size later during runtime if we want to. The example below initializes the arraylist with 50 elements:  \nArrayList\u003CInteger> a = new ArrayList\u003CInteger> (50);  \nHere are methods to manipulate data in an arraylist:  \npublic boolean add (BaseType newElement)  \nAdds a new object to the end of the arraylist.  \nRecall that all classes are derived from class Object, therefore all classes are supported as parameters for this method.  \npublic void add(int index, BaseType newElement)  \nInserts the newElement at position index and pushes everything else after this object down by one in the arraylist.  \npublic void set(int index, BaseType newElement)  \nSets an existing element at position index to newElement.  \nIndex starts at 0.  \nAn element at this index must previously exist (i.e. can’t use  \nto add to a new position)  \npublic BaseType get(int index)  \nReturns the object at position index  \nIndex starts at 0.  \npublic BaseType remove(int index)  \nDeletes the element at position index and moves everything else  \nafter this object up by one in the arraylist. Returns the object removed.  \npublic int indexOf(Object target)  \nReturns the index of the first element equal to target or-1 if not found. This method invokes the equals() method of the object, so if your object does not implement and override equals() inherited from class object, most likely this method will not work properly!  \npublic void remove(BaseType element)  \nRemoves element from the arraylist by first searching for it using the equals method. Requires that equals be overridden.  \npublic int size()  \nReturns the number of elements placed in","cbCaikxzpKvl5V7y","https://ap.wps.com/l/cbCaikxzpKvl5V7y","pdf",144120,"English","# ArrayLists\n## Dynamic Arrays vs Fixed-Size Arrays\n## Why Use Arrays Instead of ArrayList\n## Creating ArrayLists with Generics\n## ArrayList Operations and Methods\n## Example Usage","[{\"question\":\"What makes Java ArrayList different from regular arrays?\",\"answer\":\"ArrayList acts like a dynamic array that can grow or shrink in size at runtime, unlike regular arrays which require a fixed size after declaration.\"},{\"question\":\"Why can ArrayList elements be objects but not primitive types directly?\",\"answer\":\"ArrayList stores objects, so primitive types like int must be wrapped (e.g., using Integer) or represented via custom object classes.\"},{\"question\":\"How do you add, insert, and update elements in an ArrayList?\",\"answer\":\"Use add(newElement) to append, add(index, newElement) to insert at a position, and set(index, newElement) to replace an existing element at that index.\"}]","ArrayLists - Introduction to Java ArrayList and Generics | PDF",18,[145],{"page_no":8,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/d5b4cf4e283c7508daed6d1aa9987513.webp",983,1272,{"list":150,"token":66},[151,157,163,168,174,180,186,192,197,203],{"doc_id":152,"doc_title":153,"file_type":137,"home_preview_img_url":154,"slug":155,"view_count":19,"category_name":30,"create_tm":156},685689,"List and ArrayList - Java Data Structure Overview","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179285/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=BDQfdrK5jX%2FzX4hvjlHbgSfBdQI%3D","list-and-arraylist-java-data-structure-overview",1794016763,{"doc_id":158,"doc_title":159,"file_type":137,"home_preview_img_url":160,"slug":161,"view_count":24,"category_name":30,"create_tm":162},685694,"Implementing an ArrayList - Part 1 - Homework/Exam Announcements","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179430/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=5WsAMXhhFu7BTmjhoaK0vMoRqX0%3D","implementing-an-arraylist-part-1-homeworkexam-announcements",1794016774,{"doc_id":164,"doc_title":165,"file_type":137,"home_preview_img_url":166,"slug":167,"view_count":19,"category_name":30,"create_tm":129},685795,"Tutorial - Arrays and ArrayList - Introduction and Examples","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000212503/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=YqKwRNHZR7aTBwSPNoY93JmRrHs%3D","tutorial-arrays-and-arraylist-introduction-and-examples",{"doc_id":169,"doc_title":170,"file_type":137,"home_preview_img_url":171,"slug":172,"view_count":19,"category_name":30,"create_tm":173},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=1796111939&Signature=KEw%2BoRjCPFTwiPqdKXXWuR7CojU%3D","arraylist-short-version",1794016761,{"doc_id":175,"doc_title":176,"file_type":137,"home_preview_img_url":177,"slug":178,"view_count":24,"category_name":30,"create_tm":179},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=1796111939&Signature=T4vno4SFMVZNKTIjwvrVM4sgg2U%3D","arraylist-in-java",1794016760,{"doc_id":181,"doc_title":182,"file_type":137,"home_preview_img_url":183,"slug":184,"view_count":29,"category_name":30,"create_tm":185},685799,"ARRAY LISTS - Lecture 17 - CS302 Introduction to Programming","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000212652/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=uywwJmT8oQuT67VaO%2F8qlRJgd9E%3D","array-lists-lecture-17-cs302-introduction-to-programming",1794018682,{"doc_id":187,"doc_title":188,"file_type":137,"home_preview_img_url":189,"slug":190,"view_count":81,"category_name":30,"create_tm":191},719599,"Introduction to Linked Lists - Part 15-121","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023815569/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=FSUILawK8cgo9oWNJi%2FRGqcXcoc%3D","introduction-to-linked-lists-part-15-121",1795006735,{"doc_id":193,"doc_title":194,"file_type":137,"home_preview_img_url":195,"slug":196,"view_count":19,"category_name":30,"create_tm":173},685688,"Lecture 11 - Arrays and ArrayLists - Introduction","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000179281/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=wE5bPc5uGHsOyhlSB3aL4AzK5o0%3D","lecture-11-arrays-and-arraylists-introduction",{"doc_id":198,"doc_title":199,"file_type":137,"home_preview_img_url":200,"slug":201,"view_count":52,"category_name":30,"create_tm":202},685794,"Core Java - Volume I - Fundamentals - Twelfth Edition","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000212435/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=rwgdm9aNFzcXduvZW%2F88veweD2E%3D","core-java-volume-i-fundamentals-twelfth-edition",1794018671,{"doc_id":204,"doc_title":205,"file_type":137,"home_preview_img_url":206,"slug":207,"view_count":19,"category_name":30,"create_tm":208},685785,"Arrays and Array Lists - Enhanced for Loop and 2D Arrays","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000208921/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=9LvbGIqeqLwaTrBNf33ie2yvyxM%3D","arrays-and-array-lists-enhanced-for-loop-and-2d-arrays",1794018474]