[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-685694-105":59,"doc-detail-685694-en":130,"doc-similar-685694":154},{"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","implementing-an-arraylist-part-1-homeworkexam-announcements","Implementing an ArrayList - Part 1 - Homework/Exam Announcements","","Course slide notes on implementing an ArrayList, including how arrays differ from ArrayLists and the core array operations and their O(1) random-access behavior. It explains how to analyze ArrayList performance by mapping size/get/set to array operations and highlighting that add/remove at an index can be O(n) in the worst case. The document also outlines a generic MyArrayList\u003CE> design with internal storage, casting from Object[], and Java-style size(), get(), set() methods with bounds checking and exception handling.",{"@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/implementing-an-arraylist-part-1-homeworkexam-announcements/685694/",{"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/implementing-an-arraylist-part-1-homeworkexam-announcements/685694.png","ImageObject",300,407,{"name":92,"@type":93},"cryingin4k","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-18","2026-11-07",true,{"@type":102,"interactionType":103,"userInteractionCount":24},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"How do arrays differ from ArrayLists?","Question",{"text":112,"@type":113},"Arrays have a fixed size and cannot store primitive data in the same way as ArrayLists. Arrays are not instances of a class, rely on special syntax, and do not provide methods like class-based objects do.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"What are the basic operations of an array and their time complexity?",{"text":117,"@type":113},"Getting an array length uses a.length, reading an element uses a[i], and setting uses a[i] = ... . These basic operations run in O(1) time, enabling random access to any index.",{"name":119,"@type":110,"acceptedAnswer":120},"Why are add/remove operations at an index potentially O(n) for ArrayLists?",{"text":121,"@type":113},"Although size/get/set are O(1) because they map to underlying array operations, shifting elements for insertions or removals requires work proportional to the number of elements, leading to O(n) worst-case performance.","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},685694,1794016774,{"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":24,"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":14,"preview_urls":145},137458181193,"https://ap-avatar.wpscdn.com/davatar_6f874abed73319feea01a86fa6f0fab8","Implementing an ArrayList  \n15-121 Fall 2020 Margaret Reid-Miller  \nAnnouncements  \n• Exam 1: Thursday, Oct 8, 2020  \n• Drop deadline: Monday, Oct 12  \n• Grades for Hw3, Quizzes & Labs should be up later this week.  \n• Homework5: out later today  \n• Part I due and Part II checkpoint due Monday, Oct 5 at 11:55 pm  \n• Part II complete due Monday Oct 12 at  \n11:55 pm  \nFall 2020 15-121 (Reid-Miller) 2  \nToday  \n• Homework 3: Note, create ONE Scanner object to read [from](from System.in)[ System.in](from System.in)  \n• ArrayList Implementation  \nFall 2020 15-121 (Reid-Miller) 3  \nArrayList Implementation  \nFall 2020 15-121 (Reid-Miller) 15  \nWhat are 3 ways arrays differ from ArrayLists?  \n• You can't change the size of an array  \n• Arrays can hold primitive data values  \n• Arrays are not instances of a class:  \n• We use a special syntax with arrays.  \n• Arrays don't have methods.  \nFall 2020 15-121 (Reid-Miller) 16  \nThe basic operations of an array:  \n• Getting the length of an array: a .length  \n• Getting an array element: a[i]  \n• Setting an array element: a[i] = …  \nAll basic array operations run in O(1) time! We often say arrays are random access because you can access or set any element of an array in the same amount of time as the first element. (At least hardware manufacturers try to make that true.)  \nFall 2020 15-121 (Reid-Miller) 17  \nAnalyzing ArrayLists  \n• We can use an array to implement an ArrayList, just like we did in the contact list application.  \n• Because arrays underlie ArrayLists, ArrayLists runtime for size / get / set is also O(1) .  \n• But add / remove at index are O(n) in the worst case.  \n• Let's see why by implementing an ArrayList.  \nRecall: When we declare and create an instance of an ArrayList, we specify its type. type argument  ArrayList\u003CPerson> contacts = new ArrayList\u003CPerson>();  \nFall 2020 15-121 (Reid-Miller) 18  \nImplementing ArrayList  \nMyArrayList is a generic class, which specifies a type parameter.  \n type parameter  \npublic class MyArrayList\u003CE> {  \nuse type parameter as type  \nprivate E[] values; private int size;  \npublic MyArrayList() {  \nvalues = (E[]) new Object[1];  \nsize = 0;}  \nNeed to cast toa generic type  \nFall 2020 15-121 (Reid-Miller) 19  \nImplementing ArrayList size & get  \n// Returns the number of elements in the list public int size() {  \nreturn size;}  \n// Returns the element at position index  \npublic E get( int index) { constructor  \n}  \nif (index \u003C 0 || index >= size)   \nthrow new ArrayIndexOutOfBoundsException(index);  \nelse  \nreturn values[index];  \nNote: \"throw \" is a Java statement, but a method header declares that it\"throws \" .  \nFall 2020 15-121 (Reid-Miller) 20  \nImplementing ArrayList set  \n// Replaces element at position index with newValue .// Returns the element previously at position index  \npublic  E  set( int index, E newValue) { if (index \u003C 0 ||  index > = size )  \nthrow new ArrayIndexOutOfBoundsException(index);  \n E  oldvalue = values[index]; // save old  \nvalues[index] = newValue ;  \nreturn oldvalue ;}  \nFall 2020 15-121 (Reid-Miller) 21","cbCaii9zUtW4Tpyd","https://ap.wps.com/l/cbCaii9zUtW4Tpyd","pdf",257098,15,"English","# Implementing an ArrayList\n## Announcements and due dates\n## Arrays vs ArrayLists\n## Basic array operations and complexity\n## Analyzing ArrayLists performance\n## Implementing a generic MyArrayList\n## Implementing size() and get()\n## Implementing set()","[{\"question\":\"How do arrays differ from ArrayLists?\",\"answer\":\"Arrays have a fixed size and cannot store primitive data in the same way as ArrayLists. Arrays are not instances of a class, rely on special syntax, and do not provide methods like class-based objects do.\"},{\"question\":\"What are the basic operations of an array and their time complexity?\",\"answer\":\"Getting an array length uses a.length, reading an element uses a[i], and setting uses a[i] = ... . These basic operations run in O(1) time, enabling random access to any index.\"},{\"question\":\"Why are add/remove operations at an index potentially O(n) for ArrayLists?\",\"answer\":\"Although size/get/set are O(1) because they map to underlying array operations, shifting elements for insertions or removals requires work proportional to the number of elements, leading to O(n) worst-case performance.\"}]","Implementing an ArrayList - Part 1 - Homework/Exam Announcements | PDF",38,[146,150],{"page_no":8,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/a9f637baf81f8f8e76c774ae2a8d5643.webp",983,737,{"page_no":14,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/27390130569f0ac66d1c678b7094927c.webp",982,736,{"list":155,"token":66},[156,162,168,174,180,186,193,199,205,210],{"doc_id":157,"doc_title":158,"file_type":137,"home_preview_img_url":159,"slug":160,"view_count":81,"category_name":30,"create_tm":161},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=1796111519&Signature=t%2Bm9dDWHw1Z0tbKkHyymGEWJifI%3D","arraylists-introduction-to-java-arraylist-and-generics",1794018675,{"doc_id":163,"doc_title":164,"file_type":137,"home_preview_img_url":165,"slug":166,"view_count":19,"category_name":30,"create_tm":167},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=1796111519&Signature=Zaq71MrMHdFlk0mAbXREJVxk%2F7w%3D","list-and-arraylist-java-data-structure-overview",1794016763,{"doc_id":169,"doc_title":170,"file_type":137,"home_preview_img_url":171,"slug":172,"view_count":24,"category_name":30,"create_tm":173},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=1796111519&Signature=Kj9IjvKQHYx%2F6VM3F3imbCuYQN0%3D","arraylist-in-java",1794016760,{"doc_id":175,"doc_title":176,"file_type":137,"home_preview_img_url":177,"slug":178,"view_count":19,"category_name":30,"create_tm":179},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=1796111519&Signature=XtZMbouJC2Z3Hl6ZpKftOfjGYMA%3D","arraylist-and-iterator-in-java-java-list-iteration-methods-and-examples",1794016767,{"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=1796111519&Signature=2QpE9A8Xl1yxlfEXxCamMbk6hQo%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":191,"category_name":30,"create_tm":192},311712,"AP Computer Science A - Java Quick Reference - Exam Reference Information","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229907590499/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111519&Signature=P%2B2gR%2FjwONAJxl5ORaG4HQmgl1w%3D","ap-computer-science-a-java-quick-reference-exam-reference-information",14,1789894691,{"doc_id":194,"doc_title":195,"file_type":137,"home_preview_img_url":196,"slug":197,"view_count":81,"category_name":30,"create_tm":198},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=1796111519&Signature=IM%2BPmekISoiIjDz4xKVW8%2FsyR8w%3D","introduction-to-linked-lists-part-15-121",1795006735,{"doc_id":200,"doc_title":201,"file_type":137,"home_preview_img_url":202,"slug":203,"view_count":19,"category_name":30,"create_tm":204},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=1796111519&Signature=VxPbAFp7PtiZ1S7m12qohBFoJLk%3D","lecture-11-arrays-and-arraylists-introduction",1794016761,{"doc_id":206,"doc_title":207,"file_type":137,"home_preview_img_url":208,"slug":209,"view_count":19,"category_name":30,"create_tm":204},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=1796111519&Signature=yJ%2B9P6O46bMF8T1Vh7gid%2FNj8Ao%3D","arraylist-short-version",{"doc_id":211,"doc_title":212,"file_type":137,"home_preview_img_url":213,"slug":214,"view_count":24,"category_name":30,"create_tm":215},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=1796111519&Signature=wgyV4UjbXo5rbDRmxheDXR8%2BT%2FA%3D","java-collections-framework-interfaces-implementations-and-core-algorithms",1794445828]