[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685785-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-685785-en":130,"doc-similar-685785":198},{"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","arrays-and-array-lists-enhanced-for-loop-and-2d-arrays","Arrays and Array Lists - Enhanced for Loop and 2D Arrays","","Material explains how a computer program stores and processes collections of values using arrays and array lists. It covers declaring arrays in two steps (declaration and initialization), reserving memory for a fixed size, and the restriction that array size cannot change without creating a new array. The guide also shows declaring and creating on one line, initializing with contents lists, using indices to access elements, and preparing to traverse arrays and array lists (including enhanced for loop) and work with two-dimensional arrays.",{"@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/arrays-and-array-lists-enhanced-for-loop-and-2d-arrays/685785/",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/arrays-and-array-lists-enhanced-for-loop-and-2d-arrays/685785.png","ImageObject",300,407,{"name":42,"@type":43},"Bintang","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-28","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},"Why must an array be initialized with a size before use?","Question",{"text":62,"@type":63},"An array cannot be used until the compiler knows its size during initialization. Without the size, the program cannot reserve the required memory.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do you declare and create an array of doubles?",{"text":67,"@type":63},"Use two steps: declare `double[] values;` and then initialize with `values = new double[10];` (or declare and create on the same line `double[] values = new double[10];`).",{"name":69,"@type":60,"acceptedAnswer":70},"How do you access an element inside an array?",{"text":71,"@type":63},"Access elements by array name and index, such as `values[i]`. Indices number elements starting from 0.","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},685785,1794018474,{"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":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":79,"read_time":144,"preview_page_count":145,"preview_urls":146},962085564381,"https://ap-avatar.wpscdn.com/davatar_6f874abed73319feea01a86fa6f0fab8","▪To collect elements using arrays and array lists  \n▪To use the enhanced for loop for traversing arrays and array lists ▪To learn common algorithms for processing arrays and array lists ▪To work with two-dimensional arrays  \n▪A Computer Program often needs to store a list of values and then process them  \n▪For example, if you had this list of values, how many variables would you need?  \n▪double input1, input2, input3….  \n▪Arrays to the rescue!  \n▪ An array collects sequences of values of the same type  \nDeclaring an array is a two step process  \n1) double[] values; // declare array variable  \n2) values = new double [10] ; // initialize array  \nYou cannot use the array until you tell the compiler the size of the array in step 2.  \n▪Make a named‘list’ with the following parts:  \nType Square Braces Array name Semicolon  \ndouble [ ] values ;  \n▪You are declaring that  \n▪There is an array named values  \n▪The elements inside are of type double  \n▪You have not (YET) declared how many elements are in inside  \n▪Other Rules:  \n▪Arrays can be declared anywhere you can declare a variable  \n▪Do not use ‘reserved’ words or already used names  \n▪Reserve memory for all of the elements:  \nArray name Keyword Type Size Semicolon  \nvalues = new double [10] ;  \n▪You are reserving memory for:  \n▪The array named values  \n▪needs storage for [10]  \n▪elements the size of type double  \n▪You are also setting up the array variable  \n▪Now the compiler knows how many elements there are  \n▪You cannot change the size after you declare it without asking for anew array!  \nvalues  \n [0] [1] [2] [3] [4] … [9]  \n\n| double | double | double | double | double | double |\n| --- | --- | --- | --- | --- | --- |\n\n▪Declare and Create on the same line:  \nType Braces Array name Keyword Type Size Semicolon  \ndouble [] values = new double[10] ;  \n▪You are declaring that  \n▪There is an array named values  \n▪The elements inside are of type double  \n▪You are reserving memory for the array  \n▪Needs storage for [10]  \n▪elements the size of type double  \n▪You are also setting up the array variable  \n▪You can declare and set the initial contents of all elements by:  \nType Braces Array name Contents list Semicolon  \nint [ ] primes = { 2, 3, 5, 7} ;  \n▪You are declaring that  \n▪There is an array named primes  \n▪The elements inside are of type int  \n▪Reserve space for four elements  \n▪The compiler counts them for you!  \n▪Set initial values to 2, 3, 5, and 7  \n▪Note the curly braces around the contents list  \n▪Each element is numbered  \n▪We call this the index  \n▪Access an element by:  \n▪Name of the array  \n▪Index number  \n▪ values[i]  \npublic static void main(String[] args){  \ndouble values[];  \nvalues = new double[10];  \nvalues[4] = 35;  \n}","cbCainryB3LGZzih","https://ap.wps.com/l/cbCainryB3LGZzih","pdf",3146518,128,"English","# Arrays and Array Lists\n## Declaring Arrays and Reserving Memory\n## Initializing Arrays and Accessing Elements\n## Enhanced for Loop and Traversal\n## Two-Dimensional Arrays","[{\"question\":\"Why must an array be initialized with a size before use?\",\"answer\":\"An array cannot be used until the compiler knows its size during initialization. Without the size, the program cannot reserve the required memory.\"},{\"question\":\"How do you declare and create an array of doubles?\",\"answer\":\"Use two steps: declare `double[] values;` and then initialize with `values = new double[10];` (or declare and create on the same line `double[] values = new double[10];`).\"},{\"question\":\"How do you access an element inside an array?\",\"answer\":\"Access elements by array name and index, such as `values[i]`. Indices number elements starting from 0.\"}]","Arrays and Array Lists - Enhanced for Loop and 2D Arrays | PDF",323,13,[147,151,155,159,163,166,170,174,178,181,185,190,195],{"page_no":22,"url":148,"width":149,"height":150},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/1e1e05c555e3661d7c778bae566620b3.webp",983,737,{"page_no":26,"url":152,"width":153,"height":154},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/09f5c75357032d98c36d829c887f332e.webp",982,736,{"page_no":30,"url":156,"width":157,"height":158},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/17726f2eeba0eb361582b2d1aad6bec4.webp",981,735,{"page_no":33,"url":160,"width":161,"height":162},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/6f7d3c707c6e1f13e59e9ef0ac69acaf.webp",980,734,{"page_no":96,"url":164,"width":165,"height":162},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/7306053541b1da89a08a6990eebe1a05.webp",979,{"page_no":101,"url":167,"width":168,"height":169},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/2507de2faa67e90d6c361985117f6f21.webp",978,733,{"page_no":105,"url":171,"width":172,"height":173},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/cad245c200e09f4a1867fc2290f4c5f9.webp",977,732,{"page_no":110,"url":175,"width":176,"height":177},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/4bfb54e6897f1a5a153efbaa467db228.webp",976,731,{"page_no":115,"url":179,"width":180,"height":177},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/b7f01704b5e373ded8a87fb0de40daca.webp",975,{"page_no":123,"url":182,"width":183,"height":184},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/cde92e706439a96b3f15f7a6a27a0fde.webp",974,730,{"page_no":186,"url":187,"width":188,"height":189},11,"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/17d0dfbb3078dd66e32e7a4e5658e37b.webp",973,729,{"page_no":191,"url":192,"width":193,"height":194},12,"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/a24d171a3c1066e2c241ddf84c308a41.webp",972,728,{"page_no":145,"url":196,"width":197,"height":194},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/9a04976d4dea88260cd46d4c48007762.webp",971,{"list":199,"token":11},[200,206,212,218,224,229,235,241,246,252],{"doc_id":201,"doc_title":202,"file_type":137,"home_preview_img_url":203,"slug":204,"view_count":33,"category_name":29,"create_tm":205},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=1796110619&Signature=T7Gk%2FjllO03Yq%2BB3NnlgHvfIyBk%3D","lecture-11-arrays-and-arraylists-introduction",1794016761,{"doc_id":207,"doc_title":208,"file_type":137,"home_preview_img_url":209,"slug":210,"view_count":30,"category_name":29,"create_tm":211},685787,"Arrays - Java Arrays vs Python Lists - Learn how to declare and use arrays in Java","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000208980/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110619&Signature=TQg%2FHdi093smIqkykv%2BZAgzAOxY%3D","arrays-java-arrays-vs-python-lists-learn-how-to-declare-and-use-arrays-in-java",1794018478,{"doc_id":213,"doc_title":214,"file_type":137,"home_preview_img_url":215,"slug":216,"view_count":33,"category_name":29,"create_tm":217},697950,"unit06-1-Arrays - Arrays in Memory Lecture Notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010141905/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110619&Signature=2bjf1QsA6Yir8zO0NqRMVELmjf0%3D","unit06-1-arrays-arrays-in-memory-lecture-notes",1794446318,{"doc_id":219,"doc_title":220,"file_type":137,"home_preview_img_url":221,"slug":222,"view_count":96,"category_name":29,"create_tm":223},685805,"Numpy - Array - Chapter 11 - Informatics Practices","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000213217/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110619&Signature=%2B%2FYRy%2BwMxouO%2FVUi0RghmwuooNM%3D","numpy-array-chapter-11-informatics-practices",1794018711,{"doc_id":225,"doc_title":226,"file_type":137,"home_preview_img_url":227,"slug":228,"view_count":105,"category_name":29,"create_tm":211},685788,"Python Arrays - Learn How to Create, Access, and Modify Lists","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999694760/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110619&Signature=Y6se2Azs5deurh6COELZvQ0nzy0%3D","python-arrays-learn-how-to-create-access-and-modify-lists",{"doc_id":230,"doc_title":231,"file_type":137,"home_preview_img_url":232,"slug":233,"view_count":33,"category_name":29,"create_tm":234},697962,"DATA STRUCTURES - Chapter 5 Basic Data Structures","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230009214987/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110619&Signature=g64LRZycwPnKOTl4A2ecFcyqoEw%3D","data-structures-chapter-5-basic-data-structures",1794446352,{"doc_id":236,"doc_title":237,"file_type":137,"home_preview_img_url":238,"slug":239,"view_count":30,"category_name":29,"create_tm":240},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=1796110619&Signature=oVs3OqemCxf%2F8%2Fmt5rx1bHNh3YQ%3D","arraylists-introduction-to-java-arraylist-and-generics",1794018675,{"doc_id":242,"doc_title":243,"file_type":137,"home_preview_img_url":244,"slug":245,"view_count":33,"category_name":29,"create_tm":240},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=1796110619&Signature=%2BYB%2FRLR5wGim57j9C4BxFW0vLz8%3D","tutorial-arrays-and-arraylist-introduction-and-examples",{"doc_id":247,"doc_title":248,"file_type":137,"home_preview_img_url":249,"slug":250,"view_count":96,"category_name":29,"create_tm":251},685716,"Linked Lists - Introduction - Properties, Advantages, Disadvantages, and Types","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999688533/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110619&Signature=dCApNYf%2Bdwx6xKqYu%2F71w%2BE%2FVQE%3D","linked-lists-introduction-properties-advantages-disadvantages-and-types",1794016969,{"doc_id":253,"doc_title":254,"file_type":137,"home_preview_img_url":255,"slug":256,"view_count":96,"category_name":29,"create_tm":257},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=1796110619&Signature=IowQF5g8LNzXm0zwRyDPzICFgMw%3D","arraylist-in-java",1794016760]