[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685687-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-685687-en":130,"doc-similar-685687":149},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","arraylist-short-version","ArrayList - Short Version","","Handout #49 introduces Java’s ArrayList as a collection that can store groups of objects and manipulate them sequentially. It explains the objects-only constraint, clarifying that ArrayLists store pointers to object instances rather than primitives. The document covers core operations through a short example: creating an empty ArrayList, adding elements with add(), and accessing elements via size() and get() using zero-based indexing. A long version begins by describing add(Object element) and its shallow-copy semantics.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/arraylist-short-version/685687/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/arraylist-short-version/685687.png","ImageObject",300,407,{"name":42,"@type":43},"aboduw","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-12","2026-11-07",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What is an ArrayList in Java and why is it useful?","Question",{"text":62,"@type":63},"An ArrayList is an object that stores a group of other objects and lets programs manipulate those stored elements one by one. It expands what Java programs can do by managing collections of objects.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"What key limitation do Java collection classes like ArrayList have?",{"text":67,"@type":63},"They can only store pointers to objects, not primitives such as int or double. As a result, ArrayList stores pointers to object types like String, Color, or other reference types.",{"name":69,"@type":60,"acceptedAnswer":70},"How do you add and access elements in an ArrayList?",{"text":71,"@type":63},"Use the add() method to add object pointers to the ArrayList. Use size() to get the number of elements and get(int index) to retrieve a specific element by its zero-based index.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},685687,1794016761,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":101,"language":139,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":12,"update_tm":79,"read_time":143,"preview_page_count":22,"preview_urls":144},3985747862266,"https://ap-avatar.wpscdn.com/davatar_085a072bc5b1113ac321206ff7593b45","CS106A, Stanford Fall, 2004-05  \nHandout \\#49 Nick Parlante  \nArrayList  \nSo far we have used many sorts of variables, but it has always been true that each variable stores one value at a time – one int or one String or one boolean. The Java ArrayList class can store a group of many objects. This capability will greatly expand what our programs can do. Java has a whole suite of a \"Collection\" classes that can store groups of objects in various ways. The ArrayList is the most famous and commonly used type of collection, and it is the one we will use the most.  \nAn ArrayList is an object that can store a group of other objects for us and allow us to manipulate those objects one by one. For example, we could use an ArrayList to store all the String names of the pizza toppings offered by a restaurant, or we could store all the URLs that make up a user's favorite sites.  \nThe Java collection classes, including ArrayList, have one major constraint: they can only store pointers to objects, not primitives. So an ArrayList can store pointers to String objects or Color objects, but an ArrayList cannot store a collection of primitives like intor double. This objects-only constraint stems from fundamental aspects of the way Java works, but as a practical matter it is not much of a problem. (Java \"arrays\" which we will study shortly are an alternative to the ArrayList, and they can store primitives.)  \nFirst we will look at a small ArrayList example to see roughly how it works, and then we will look at the real syntax.  \nArrayList – Short Version  \nAn ArrayList is just an object, so we will create it like any other object – calling \"new\"and storing a pointer to the new ArrayList. When first created, the ArrayList is empty – it does not contain any objects. Traditionally, the things stored inside of a collection are called \"elements\" in the collection. However in Java, collections always store pointers to objects, so we can also use the words \"pointers\" or \"objects\" to refer to the elements in a collection.  \nThis code creates a new, empty ArrayList...  \nArrayList list = new ArrayList(); // make a new ArrayList (initially empty)  \nTo add an object to the ArrayList, we call the add() method on the ArrayList, passing a pointer to the object we want to store. This code adds pointers to three String objects to the ArrayList...  \nlist .add( \"Easy\" ); // Add three strings to the ArrayList list .add( \"does\" );  \nlist .add( \"it\" );  \n2  \nAt this point, the ArrayList contains the three pointers, each pointing to a String object...  \nlist  \nArrayList 0 1 2  \nIndex Numbers  \nHow can we identify each of the three elements in the ArrayList? The ArrayList gives each element an \"index number\". The first element added is called number 0, the next added is number 1, the next is number 2, and so on (the index numbers are shown in the drawing above) . The index numbers identify the individual elements, so we can do things with them. This \"zero based indexing\" scheme is extremely common in Computer Science, so it's worth getting accustomed to it. (Indeed, it is the same numbering scheme used to identify individual chars within a String.)  \nThe ArrayList responds to two methods that allow us to look at the elements individually. The size() method returns the int current number of elements in the ArrayList. The get() method takes an int index argument, and returns the pointer at that index number.  \nint len = list .size(); // size() returns 3 – number of elements  \nSystem.out.println( list.get(0) ); // prints \"Easy\"  \nSystem.out.println( list.get(2) ); // prints \"it\"  \nWith the size() method, we can see how many elements there are. With the get() method, we can retrieve any particular element by its index. Since the elements are numbered contiguously starting with 0, the valid index numbers will start with 0 and continue up through size()-1 . So if size() returns 3, the valid index numbers are 0, 1, and 2.  \nSo the basic use of an ArrayList reduces to creating i","cbCaih4uJFQlG35L","https://ap.wps.com/l/cbCaih4uJFQlG35L","pdf",123176,"English","# ArrayList - Short Version\n## Creating an empty ArrayList\n## Adding elements with add()\n## Index numbers and zero-based indexing\n## Reading elements with size() and get()\n# ArrayList - Long Version\n## add(Object element) method prototype\n## Objects-only constraint and pointers\n## Shallow pointers and memory structure\n## size() method details","[{\"question\":\"What is an ArrayList in Java and why is it useful?\",\"answer\":\"An ArrayList is an object that stores a group of other objects and lets programs manipulate those stored elements one by one. It expands what Java programs can do by managing collections of objects.\"},{\"question\":\"What key limitation do Java collection classes like ArrayList have?\",\"answer\":\"They can only store pointers to objects, not primitives such as int or double. As a result, ArrayList stores pointers to object types like String, Color, or other reference types.\"},{\"question\":\"How do you add and access elements in an ArrayList?\",\"answer\":\"Use the add() method to add object pointers to the ArrayList. Use size() to get the number of elements and get(int index) to retrieve a specific element by its zero-based index.\"}]","ArrayList - Short Version | PDF",15,[145],{"page_no":22,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/fade19b701074bf78d873d1f874f0470.webp",983,1272,{"list":150,"token":11},[151,157,163,169,175,181,187,192,198,204],{"doc_id":152,"doc_title":153,"file_type":137,"home_preview_img_url":154,"slug":155,"view_count":30,"category_name":29,"create_tm":156},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=1796111639&Signature=gYgl%2BrgPs%2Bqok2kpisTGY7I%2FxKQ%3D","arraylists-introduction-to-java-arraylist-and-generics",1794018675,{"doc_id":158,"doc_title":159,"file_type":137,"home_preview_img_url":160,"slug":161,"view_count":101,"category_name":29,"create_tm":162},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=1796111639&Signature=n0RsnziY6gZI680E%2FuwPcrUWUss%3D","array-lists-lecture-17-cs302-introduction-to-programming",1794018682,{"doc_id":164,"doc_title":165,"file_type":137,"home_preview_img_url":166,"slug":167,"view_count":96,"category_name":29,"create_tm":168},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=1796111639&Signature=l%2FiGeWmwMbRM8p3UmJHgU6EvteA%3D","implementing-an-arraylist-part-1-homeworkexam-announcements",1794016774,{"doc_id":170,"doc_title":171,"file_type":137,"home_preview_img_url":172,"slug":173,"view_count":115,"category_name":29,"create_tm":174},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=1796111639&Signature=wZrVVPU5pC8uojFTaCZPhXoGxcs%3D","core-java-volume-i-fundamentals-twelfth-edition",1794018671,{"doc_id":176,"doc_title":177,"file_type":137,"home_preview_img_url":178,"slug":179,"view_count":30,"category_name":29,"create_tm":180},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=1796111639&Signature=XLQOzpJ206PlL5iiQY58s9gvlUM%3D","introduction-to-linked-lists-part-15-121",1795006735,{"doc_id":182,"doc_title":183,"file_type":137,"home_preview_img_url":184,"slug":185,"view_count":26,"category_name":29,"create_tm":186},719605,"Linked Lists - lecture notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023815899/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111639&Signature=QZ2pOllDgb%2BLkRM0%2FqlHf5w%2FFiM%3D","linked-lists-lecture-notes",1795006752,{"doc_id":188,"doc_title":189,"file_type":137,"home_preview_img_url":190,"slug":191,"view_count":33,"category_name":29,"create_tm":156},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=1796111639&Signature=IFr%2FylNz4zidOStSdmkC%2BGFctrA%3D","tutorial-arrays-and-arraylist-introduction-and-examples",{"doc_id":193,"doc_title":194,"file_type":137,"home_preview_img_url":195,"slug":196,"view_count":33,"category_name":29,"create_tm":197},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":199,"doc_title":200,"file_type":137,"home_preview_img_url":201,"slug":202,"view_count":33,"category_name":29,"create_tm":203},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":205,"doc_title":206,"file_type":137,"home_preview_img_url":207,"slug":208,"view_count":96,"category_name":29,"create_tm":209},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]