[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685689-105":3,"detail-sidebar-cat-0-en-105":84,"doc-detail-685689-en":134,"doc-similar-685689":162},{"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":77,"head_meta":79,"extra_data":81,"updated_unix":83},105,"en","list-and-arraylist-java-data-structure-overview","List and ArrayList - Java Data Structure Overview","","Covers the difference between arrays, the List interface, and the Java ArrayList class, focusing on why dynamic sizing matters. Explains how arrays require a known size up front and cannot change length after allocation. Demonstrates ArrayList behavior: ordered storage, automatic growth/shrinkage, and methods like add, remove, get, size, and indexOf. Compares untyped ArrayList and typed ArrayList\u003CString>, highlighting the need for casting in the first case and how generics avoid ClassCastException at compile time.",{"@graph":14,"@context":76},[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/list-and-arraylist-java-data-structure-overview/685689/",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/list-and-arraylist-java-data-structure-overview/685689.png","ImageObject",300,407,{"name":42,"@type":43},"cksankcs","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-18","2026-11-07",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68,72],{"name":59,"@type":60,"acceptedAnswer":61},"Why can’t you resize a Java array after creating it?","Question",{"text":62,"@type":63},"When you create an array, you allocate its capacity immediately. The array’s size remains fixed, so you cannot change the length after allocation.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"What is the relationship between ArrayList and the List interface?",{"text":67,"@type":63},"List is an interface that defines required behaviors (like add, remove, contains, indexOf). ArrayList is a class that implements List, meaning it provides the behaviors specified by the interface.",{"name":69,"@type":60,"acceptedAnswer":70},"What problem occurs with an untyped ArrayList (raw ArrayList)?",{"text":71,"@type":63},"An untyped ArrayList stores elements as Objects, so get() returns Object. To retrieve a specific type you must cast, which can fail at runtime with a ClassCastException if the element is not actually of that type.",{"name":73,"@type":60,"acceptedAnswer":74},"How does ArrayList\u003CString> improve safety compared to raw ArrayList?",{"text":75,"@type":63},"Using ArrayList\u003CString> applies a type parameter so the compiler restricts added elements to String. Retrieval returns the correct type without requiring casts, reducing the chance of runtime type errors.","https://schema.org",{"og:url":32,"og:type":78,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":80,"canonical":32},"index,follow",{"doc_id":82,"site_id":7},685689,1794016763,{"code":4,"msg":85,"data":86},"success",[87,91,95,99,104,108,113,118,123,126,130],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":96,"show_sort_weight":97,"slug":98},"Exam",70,"exam",{"id":100,"doc_module":4,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},5,"Comic",60,"comic",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":106,"slug":107},6,50,"technology",{"id":109,"doc_module":4,"doc_module_name":25,"category_name":110,"show_sort_weight":111,"slug":112},7,"Healthcare",40,"healthcare",{"id":114,"doc_module":4,"doc_module_name":25,"category_name":115,"show_sort_weight":116,"slug":117},8,"Research & Report",30,"research-report",{"id":119,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":121,"slug":122},9,"Religion & Spirituality",20,"religion-spirituality",{"id":121,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":121,"slug":125},"World Cup","world-cup",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":127,"slug":129},10,"Lifestyle","lifestyle",{"id":131,"doc_module":4,"doc_module_name":25,"category_name":132,"show_sort_weight":100,"slug":133},19,"General","general",{"code":4,"msg":85,"data":135},{"doc_id":82,"user_id":136,"nickname":42,"user_avatar":137,"doc_module":4,"category_id":105,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":138,"file_id":139,"file_url":140,"file_type":141,"file_size":142,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":143,"language":144,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":145,"faqs":146,"seo_title":147,"seo_description":12,"update_tm":83,"read_time":148,"preview_page_count":30,"preview_urls":149},3985747882755,"https://ap-avatar.wpscdn.com/davatar_29158cc5080c5b710cf443261637dec0","List and ArrayList  \nJames Brucker  \nLimitations of Arrays  \nYou allocate space for array when you create it:  \nnumWords = console.nextInt() ;  \nString [ ] words = new String[numWords];  \nWhat if you don't know the size of data in advance?  \nExample: reading words from a file, but you don't know how many words are in the file?  \nAfter you create an array, you cannot change the size .  \nArrayList  \nArrayList is an alternative:  \n􀀁 an ordered collection of elements  \n􀀁 grows and shrinks as needed!  \n􀀁 can add, delete, replace objects anywhere  \n􀀁 ArrayList is a class in Java  \nArrayList food = new ArrayList( ); food .size(); // returns 0. Its empty food.add(\"Apple\");  \nfood.add(\"Banana\");  \nfood .size(); // returns 2  \nSystem.out.println( food.get(0) ); // Apple  \nSystem.out.println( food.get(1) ); // Banana  \nList and ArrayList  \nList is an interface that defines behavior of all list classes .  \n􀀁 specifies that a list must have: add( ), remove( ), contains( ), indexOf( ), etc .  \n􀀁 you cannot create \"List\" objects  \nArrayList is a class that implements the List interface  \n􀀁 ArrayList is a kind of List  \n􀀁 ArrayList provides all the behavior (methods) specified by the List interface  \nList in Python & Java  \nlist = [] Python  \nlist .append(\"apple\")  \nlist .append(\"banana\")  \nlen(list) \\# = 2  \nlist[0] \\# \"apple\"  \ndel(list[0]) \\# delete apple  \nArrayList list = new ArrayList(); Java list .add(\"apple\");  \nlist .add(\"banana\");  \nlist .size() // = 2  \nlist.get(0) // \"apple\"  \nlist .remove(0) // delete apple  \nUntyped ArrayList holds Objects  \n• A plain \"ArrayList\" accepts any kind of Object  \n• \"get\" always returns type Object  \nArrayList list = new ArrayList( ); list.add( \"Apple\" ); // a string  \nlist.add( [LocalDate.now](LocalDate.now) () ); // LocalDate object list.add( new Double(3.14) ); // another object  \n// Get something from arraylist  \nObject obj = list.get(1);  \n// If you want a String you must use a  cast  \nString fruit = (String) list.get(0);  \n cast  \nProblem with List  \nA basic List can contain any type of object!  \nArrayList list = new ArrayList( ); list.add ( \"apple \" ); // String  \nlist.add( new Date() ); // Date object list.add( new Long(10) ); // Long object list.add( new Coin(5) ); // Coin  \nObject obj = list.get(1); // always returns object  \nlist.get() requires a cast  \nTo get a particular kind of object, we have to cast the result to the type we want.  \nThis can cause errors .  \nArrayList list = new ArrayList( ); list.add ( \"apple \" ); // String  \nlist.add( something );  \n...  \nString x = (String)list.get(0); // cast to String  \nUsing a cast is dangerous  \n• To get a \"String\" from list, we cast the result to String.  \n• What if the object is not a String?  \n// Get a string  \nString fruit = (String) list.get(0);  \n// If get(1)  not a String, an Exception occurs String fruit2 = (String) list.get(1);  \njava.lang .ClassCastException: line 5  \nTyped ArrayList  \n• Arraylist for String only: ArrayList\u003CString>  \n• \u003CString> is called a type parameter .  \n• Type can be a class or interface, but not primitive  \nArrayList\u003CString> fruit =  \nnew ArrayList\u003CString> ( );  \nlist.add( \"Apple\" ); // a string list.add( \"Orange\" ); // string list.add( new Double(3.14) ); // Error  \n// Compiler will not allow to add a Double  \n// No cast! Result is automatically String  \nString s = list.get(1); // No cast!","cbCaiqLWBUB7sVcE","https://ap.wps.com/l/cbCaiqLWBUB7sVcE","pdf",203496,23,"English","# Limitations of Arrays\n## ArrayList as a Dynamic Alternative\n# List and ArrayList Concepts\n## Python vs Java List Operations\n# Untyped ArrayList and Casting Risks\n## ClassCastException Example\n# Typed ArrayList with Generics\n## ArrayList\u003CString> and Compile-Time Safety","[{\"question\":\"Why can’t you resize a Java array after creating it?\",\"answer\":\"When you create an array, you allocate its capacity immediately. The array’s size remains fixed, so you cannot change the length after allocation.\"},{\"question\":\"What is the relationship between ArrayList and the List interface?\",\"answer\":\"List is an interface that defines required behaviors (like add, remove, contains, indexOf). ArrayList is a class that implements List, meaning it provides the behaviors specified by the interface.\"},{\"question\":\"What problem occurs with an untyped ArrayList (raw ArrayList)?\",\"answer\":\"An untyped ArrayList stores elements as Objects, so get() returns Object. To retrieve a specific type you must cast, which can fail at runtime with a ClassCastException if the element is not actually of that type.\"},{\"question\":\"How does ArrayList\\u003cString\\u003e improve safety compared to raw ArrayList?\",\"answer\":\"Using ArrayList\\u003cString\\u003e applies a type parameter so the compiler restricts added elements to String. Retrieval returns the correct type without requiring casts, reducing the chance of runtime type errors.\"}]","List and ArrayList - Java Data Structure Overview | PDF",58,[150,154,158],{"page_no":22,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/4459160e63013fd77e472c1792c4071d.webp",983,737,{"page_no":26,"url":155,"width":156,"height":157},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/04811e7f69ed407811a1b1d5f4d8c424.webp",982,736,{"page_no":30,"url":159,"width":160,"height":161},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/14fcdee205cd1ea4b57ddf264f3ba19c.webp",981,735,{"list":163,"token":11},[164,170,177,183,189,195,201,207,213,220],{"doc_id":165,"doc_title":166,"file_type":141,"home_preview_img_url":167,"slug":168,"view_count":30,"category_name":29,"create_tm":169},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=1796111939&Signature=kYLoeUGSbyDFu%2FGmpgtOpBtFtTw%3D","arraylists-introduction-to-java-arraylist-and-generics",1794018675,{"doc_id":171,"doc_title":172,"file_type":141,"home_preview_img_url":173,"slug":174,"view_count":175,"category_name":29,"create_tm":176},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=1796111939&Signature=BB2Y3hQYCqVo2qi35FocFXRCZVs%3D","ap-computer-science-a-java-quick-reference-exam-reference-information",14,1789894691,{"doc_id":178,"doc_title":179,"file_type":141,"home_preview_img_url":180,"slug":181,"view_count":100,"category_name":29,"create_tm":182},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":184,"doc_title":185,"file_type":141,"home_preview_img_url":186,"slug":187,"view_count":100,"category_name":29,"create_tm":188},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":190,"doc_title":191,"file_type":141,"home_preview_img_url":192,"slug":193,"view_count":33,"category_name":29,"create_tm":194},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=1796111939&Signature=7815v6VzQUfeAI6k6x8vH6ky5MU%3D","arraylist-and-iterator-in-java-java-list-iteration-methods-and-examples",1794016767,{"doc_id":196,"doc_title":197,"file_type":141,"home_preview_img_url":198,"slug":199,"view_count":100,"category_name":29,"create_tm":200},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=1796111939&Signature=UJXcDm1dGqm%2Fe4uK2u6i70hN4Mw%3D","java-collections-framework-interfaces-implementations-and-core-algorithms",1794445828,{"doc_id":202,"doc_title":203,"file_type":141,"home_preview_img_url":204,"slug":205,"view_count":105,"category_name":29,"create_tm":206},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":208,"doc_title":209,"file_type":141,"home_preview_img_url":210,"slug":211,"view_count":175,"category_name":29,"create_tm":212},491210,"A container library for C - A C container library overview","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229928140490/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=WFR8AIcPrghxKTgf0%2F2MhpgX6BQ%3D","a-container-library-for-c-a-c-container-library-overview",1790846909,{"doc_id":214,"doc_title":215,"file_type":141,"home_preview_img_url":216,"slug":217,"view_count":218,"category_name":29,"create_tm":219},423014,"THE JAVA LANGUAGE CHEAT SHEET - quick reference","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229922611453/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111939&Signature=hBhDFe0HbqABHsr6Mz1DupN7ItM%3D","the-java-language-cheat-sheet-quick-reference",13,1790629749,{"doc_id":221,"doc_title":222,"file_type":141,"home_preview_img_url":223,"slug":224,"view_count":33,"category_name":29,"create_tm":169},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"]