[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-685799-105":59,"doc-detail-685799-en":130,"doc-similar-685799":158},{"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","array-lists-lecture-17-cs302-introduction-to-programming","ARRAY LISTS - Lecture 17 - CS302 Introduction to Programming","","Lecture notes for CS302 “Introduction to Programming” focusing on Java ArrayLists: what they are, how they differ from fixed-size arrays, and how to declare, create, and use ArrayList objects for a single data type. The material explains the add() method for inserting compatible elements, the get() method for indexed access with warnings about invalid indices, and the ability of ArrayLists to grow automatically as more elements are added. Includes examples and a question identifying an error in minimal code.",{"@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/array-lists-lecture-17-cs302-introduction-to-programming/685799/",{"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/array-lists-lecture-17-cs302-introduction-to-programming/685799.png","ImageObject",300,407,{"name":92,"@type":93},"Dipper","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-25","2026-11-07",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 is an ArrayList in Java, and how is it different from an array?","Question",{"text":112,"@type":113},"An ArrayList is an object that stores multiple elements of the same data type. Unlike arrays, ArrayLists can grow and shrink as needed.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"How do you declare and create an ArrayList of a given data type?",{"text":117,"@type":113},"Create an ArrayList variable using the ArrayList\u003Cdata type> syntax and use the new operator, e.g., ArrayList\u003CString> names = new ArrayList\u003CString>().",{"name":119,"@type":110,"acceptedAnswer":120},"How do you add and access elements in an ArrayList?",{"text":121,"@type":113},"Add elements with add(), ensuring they are compatible with the ArrayList’s data type. Access elements using get(index), and avoid invalid indices.","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},685799,1794018682,{"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":81,"preview_urls":145},1374404997633,"https://ap-avatar.wpscdn.com/davatar_a8503ba1806abce46bf441b54a3ca4cd","# ARRAY LISTS\n\nCS302 – Introduction to ProgrammingUniversity of Wisconsin – MadisonLecture 17  \nBy Matthew Bernstein – matthewb@cs.wisc.edu  \n## Array Lists\n\n• Array Lists are objects, like arrays, that storemultiple elements of the same data type  \n• Unlike arrays, array lists can grow and shrinkas needed  \n• The array list class supplies methods forcommon tasks such as inserting and removingelements  \n## Declaring and Creating Array Lists\n\n• You create an array list as follows:  \nArrayList \u003Cdata type > variable  name = new ArrayList \u003Cdata type>()  \nThe data type thatthe array list willstore  \n  \nThe name of thearray list variable  \nThe new operatoris required tocreate the array list  \nThe data type thatthe array list willstore  \n## Example Creating an Array List\n\n• The following statement creates a new, empty, arraylist, called “names”that stores Strings:  \nArrayList\u003CString> names = new ArrayList\u003CString>();  \n## Adding Elements\n\n• We add values using the array list’s add() method  \n• Values you add to the array list must be compatible withthe data type that the array list is capable of storing  \n• Example:  \n// Create the array list  \nArrayList\u003CString> names = new ArrayList\u003CString>();  \n// Add the String “Harry”to the array list  \nnames.add(“Harry”);  \n## Find the Error\n\n• What is wrong with the following code?  \nArrayList\u003CString> names;names.add(“Harry”);  \n## Array Lists Grow Automatically\n\n• We can keep adding elements to the array list“indefinitely” andthe array list will grow to accommodatethe new elements  \n• Example:  \nArrayList\u003CString> names = new ArrayList\u003CString>();  \nnames.add(“Harry”); // names now has 1 elementnames.add(“Jeremy”); // names now has 2 elementsnames.add(“Abe”); // names now has 3 elements  \n## Accessing Elements\n\n• Once we add elements to an array list, we can accesselements using the array list’s get() method  \n• The get method returns an element at a specified index ofthe array list  \n• Do not attempt to retrieve an element from an invalidindex  \n• Example:  \nnames.get(3); // Will return the element atthe 3 rd// index of the array list  \n## Example Accessing Elements\n\nArrayList\u003CString> names = new ArrayList\u003CString>();names.add(“Harry”);  \nnames.add(“Emily”);  \nnames.add(“Cindy”);  \nString thirdName = names.get(2); // Will store “Cindy”  \n## Array Lists are Reference Types\n\n• When you declare an array list variable, thevariable itself does not store any values.Rather, the variable points to the location inmemory of the array list object.  \n• In the Java programming language, allobjects are reference types","cbCaic1iPRLikQ51","https://ap.wps.com/l/cbCaic1iPRLikQ51","pdf",1853876,22,"English","# Array Lists\n# Declaring and Creating Array Lists\n# Example Creating an Array List\n# Adding Elements\n# Find the Error\n# Array Lists Grow Automatically\n# Accessing Elements\n# Example Accessing Elements\n# Array Lists are Reference Types","[{\"question\":\"What is an ArrayList in Java, and how is it different from an array?\",\"answer\":\"An ArrayList is an object that stores multiple elements of the same data type. Unlike arrays, ArrayLists can grow and shrink as needed.\"},{\"question\":\"How do you declare and create an ArrayList of a given data type?\",\"answer\":\"Create an ArrayList variable using the ArrayList\\u003cdata type\\u003e syntax and use the new operator, e.g., ArrayList\\u003cString\\u003e names = new ArrayList\\u003cString\\u003e().\"},{\"question\":\"How do you add and access elements in an ArrayList?\",\"answer\":\"Add elements with add(), ensuring they are compatible with the ArrayList’s data type. Access elements using get(index), and avoid invalid indices.\"}]","ARRAY LISTS - Lecture 17 - CS302 Introduction to Programming | PDF",55,[146,150,154],{"page_no":8,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/ee149e361f03aa6adbcc55429b5a79c8.webp",983,737,{"page_no":14,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/bf3339a3ddf6d8b9577edaf60d8a0de7.webp",982,736,{"page_no":81,"url":155,"width":156,"height":157},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/ba6702bb15312bcc1275d7cb80b538df.webp",981,735,{"list":159,"token":66},[160,166,172,178,184,190,196,202,208,214],{"doc_id":161,"doc_title":162,"file_type":137,"home_preview_img_url":163,"slug":164,"view_count":81,"category_name":30,"create_tm":165},685796,"ArrayLists - Introduction to Java ArrayList and Generics","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000212466/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=9ZeA9mUXp7TH%2BQK7uKU4k5UPf9s%3D","arraylists-introduction-to-java-arraylist-and-generics",1794018675,{"doc_id":167,"doc_title":168,"file_type":137,"home_preview_img_url":169,"slug":170,"view_count":19,"category_name":30,"create_tm":171},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=1796111999&Signature=3UzE6cQq2cNAhJpeXlEO0wCkjek%3D","arraylist-and-iterator-in-java-java-list-iteration-methods-and-examples",1794016767,{"doc_id":173,"doc_title":174,"file_type":137,"home_preview_img_url":175,"slug":176,"view_count":24,"category_name":30,"create_tm":177},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=1796111999&Signature=JExJyRx0La%2BhLgIOpZwSOXY%2FjIE%3D","arraylist-in-java",1794016760,{"doc_id":179,"doc_title":180,"file_type":137,"home_preview_img_url":181,"slug":182,"view_count":24,"category_name":30,"create_tm":183},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=1796111999&Signature=xA%2F222izoWkZ59iF8Xj5eqcfDQ0%3D","implementing-an-arraylist-part-1-homeworkexam-announcements",1794016774,{"doc_id":185,"doc_title":186,"file_type":137,"home_preview_img_url":187,"slug":188,"view_count":19,"category_name":30,"create_tm":189},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=1796111999&Signature=cCL6FmNLDgjNVYdkRLrN0JPzXSI%3D","arraylist-vs-linkedlist-for-introduction-to-java-programming-performance-comparison",1794016770,{"doc_id":191,"doc_title":192,"file_type":137,"home_preview_img_url":193,"slug":194,"view_count":19,"category_name":30,"create_tm":195},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=1796111999&Signature=tgvhZD72YWlr79sZrUB5%2BUSbjJA%3D","list-and-arraylist-java-data-structure-overview",1794016763,{"doc_id":197,"doc_title":198,"file_type":137,"home_preview_img_url":199,"slug":200,"view_count":19,"category_name":30,"create_tm":201},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=1796111999&Signature=R7AKq5jiY1UNuyt5tJ6D6i3b8gs%3D","lecture-11-arrays-and-arraylists-introduction",1794016761,{"doc_id":203,"doc_title":204,"file_type":137,"home_preview_img_url":205,"slug":206,"view_count":81,"category_name":30,"create_tm":207},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=1796111999&Signature=%2FjtbETsrAexKTI1BbXN2XFHVzyI%3D","introduction-to-linked-lists-part-15-121",1795006735,{"doc_id":209,"doc_title":210,"file_type":137,"home_preview_img_url":211,"slug":212,"view_count":29,"category_name":30,"create_tm":213},697916,"Java Collections - List Set Map","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010130865/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=Bpf7YkSCMYH9F9zKUxou4DR%2FCzc%3D","java-collections-list-set-map",1794445817,{"doc_id":215,"doc_title":216,"file_type":137,"home_preview_img_url":217,"slug":218,"view_count":19,"category_name":30,"create_tm":201},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=1796111999&Signature=NpBH%2BaCRa29TPTbWtBHD8a5%2FGhA%3D","arraylist-short-version"]