[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685688-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-685688-en":130,"doc-similar-685688":154},{"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","lecture-11-arrays-and-arraylists-introduction","Lecture 11 - Arrays and ArrayLists - Introduction","","Lecture 11 explains arrays and ArrayLists with a focus on core Java array concepts: arrays as a simple data structure storing values of the same type, index rules starting at 0, fixed array length after declaration, and supported initialization styles. It covers copying arrays using System.arraycopy, contrasts copying data vs copying references, and demonstrates two looping techniques over arrays (index-based for control and enhanced for for simplicity).",{"@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/lecture-11-arrays-and-arraylists-introduction/685688/",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/lecture-11-arrays-and-arraylists-introduction/685688.png","ImageObject",300,407,{"name":42,"@type":43},"gewufjwa","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-13","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 array in Java and how are arrays declared?","Question",{"text":62,"@type":63},"Arrays are a simple data structure that stores a set of values of the same type in Java. They are declared like other objects (e.g., int[] intArray = new int[20];).","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do array copying and array references differ?",{"text":67,"@type":63},"Copying an array can be done with System.arraycopy to create a separate data copy. Assigning a reference (int[] newArray = intArray;) makes both variables point to the same underlying array data.",{"name":69,"@type":60,"acceptedAnswer":70},"What are the two ways to loop over arrays in this lecture?",{"text":71,"@type":63},"One way uses an index-based for loop to iterate over part of the array and compute using the index (doubleArray[i]). The simpler way uses the enhanced for loop (for each double d in the array) to iterate over the entire array without an explicit 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},685688,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":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":26,"preview_urls":145},3985747882900,"https://ap-avatar.wpscdn.com/davatar_9964176cb1d06d4a9deccf72a44ae3dc","1.00 Lecture 11  \nArrays and ArrayLists  \nReading for next time: Big Java: sections 13.1-13.4  \nArrays  \n• Arrays are a simple data structure  \n• Arrays store a set of values of the same type  \n– Built-in types (int, double, etc.) or  \n– Objects (Students, Engines, etc.)  \n• Arrays are part of the Java language  \n– Arrays are objects, not primitives like int or double.  \n– They are declared in the same way as other objectsint[] intArray= new int[20]; // 􀀂 Irregular verb 􀀂  \n– The array object has an int data member, length, that gives the number of elements in the array:  \nint aSize= intArray.length; // aSize= 20  \n• Each value is accessed through an index intArray[0]= 4; intArray[1]= 77;  \nArrays, p.2  \n• Array index always starts at 0, not 1  \n– An array with N slots has indices 0 through N-1  \n– intArray has elements intArray[0] through intArray [19]  \n• Array lengths cannot be changed once they are declared  \n• Arrays can be initialized when declared int[] intArray= {5, 77, 4, 9, 28, 0, -9};// 􀀁 new 􀀂 is implicit (not needed) in this case  \n• Arrays of numerical values are zero when constructed  \nCopying arrays  \n– To copy an array, use arraycopy( ) method of System class:  \nint[] intArray= new int[20]; // Same as first slide int[] newArray= new int[intArray.length]  \n// arraycopy(fromArray, fromIndex, toArray, toIndex, count) System .arraycopy(intArray, 0, newArray, 0, intArray.length);  \n// Now intArray and newArray have separate copies of data  \n// Arrays don 􀀂 t have to be same length as long as segment // copied fits into destination array  \n\n| Copying entire array\u003Cbr>int[ ] intArray= { 5, 77, 4, 9, 28, 0, 9 };\u003Cbr>int[ ] newArray = new int[ intArray .length ];\u003Cbr>System .arraycopy(intArray, 0, newArray, 0, intArray.length) |  |\n| --- | --- |\n| intArray \u003Cbr>\u003Cbr>5 77 4 9 28 0 9 | \u003Cbr>5 77 4 9 28 0 9 |\n\n\n| Copying an array reference |  |\n| --- | --- |\n| intArray\u003Cbr>\u003Cbr>5\u003Cbr>77 4 9 28 0 9\u003Cbr>newArray\u003Cbr>| int[ ] intArray= {5, 77, 4, 9, 28, 0, 9}; int[ ] newArray = intArray; |\n\nLooping Over Arrays  \n• If doubleArray is a reference to array of doubles, there are two ways to iterate over it.  \n– This way gives more control—you can loop over just part of it, and you know what element (i) is being computed:  \ndouble sum = 0 .0;  \nfor( int i= 0; i \u003C doubleArray.length; i++)  \nsum += doubleArray[i];  \n– This way is simpler but you can only iterate over the entire array, and you don 􀀂 t have a loop counter (e.g., i) :  \ndouble sum = 0 .0;  \n// 􀀃 for each 􀀄 double d in array doubleArray for( double d : doubleArray)  \nsum += d;  \nTest Your Knowledge  \n1. Which of the following expressions does not declare and construct an array?  \na. int[] arr = new int[4]; b. int[] arr;  \narr = new int [4];  \nc. int[] arr = {1,2,3,4}; d. int[] arr;  \n2. Given this code fragment: int j= ? ;  \nint [] data = new int [ 10 ] ;  \nSystem .out .print (data [ j ]) ; Which of the following is a legal value of j? a. -1  \nb. 0  \nc. 1.5  \nd. 10  \n\n| Test Your Knowledge |  |\n| --- | --- |\n| 3. Given this code fragment:\u003Cbr>int[] arrayA = new int[4]; int[] arrayB;\u003Cbr>arrayB = arrayA;\u003Cbr>arrayB[2]=4;\u003Cbr>arrayA[0]=arrayB[2]; | What are the values of the elements in array A?\u003Cbr>a. unknown b. 0,0,0,0 c. 4,0,4,0 d. 4,0,0,0 |\n| 4. How many objects are present after\u003Cbr>the following code fragment has executed?\u003Cbr>double [] arrayA= new double [ 10 ] ; double [] array B ;\u003Cbr>array B = arrayA ; | a. 1\u003Cbr>b. 2\u003Cbr>c. 10\u003Cbr>d. 20 |\n\n\n| Test Your Knowledge\u003Cbr>5. For which of these applications an array is NOT suitable?\u003Cbr>a. Holding the scores on 4 quarters of a Basketball game\u003Cbr>b. Holding the name, account balance and account number of an individual\u003Cbr>c. Holding temperature readings taken every hour through a day\u003Cbr>d. Holding monthly expenses through a year |  |\n| --- | --- |\n| 6. Given the following code fragment: int [] data = { 1 , 3 , 5 , 7 , 11 } ; for (______________________ )\u003Cbr>System .out .print ln (data [ index ] ) ;\u003Cbr>Fill in the blanks so that the program pri","cbCaibhBPfX00UeH","https://ap.wps.com/l/cbCaibhBPfX00UeH","pdf",99631,13,"English","# Lecture 11\n## Arrays and ArrayLists\n## Arrays\n## Copying arrays\n## Looping over Arrays\n## Test Your Knowledge\n## Exercise","[{\"question\":\"What is an array in Java and how are arrays declared?\",\"answer\":\"Arrays are a simple data structure that stores a set of values of the same type in Java. They are declared like other objects (e.g., int[] intArray = new int[20];).\"},{\"question\":\"How do array copying and array references differ?\",\"answer\":\"Copying an array can be done with System.arraycopy to create a separate data copy. Assigning a reference (int[] newArray = intArray;) makes both variables point to the same underlying array data.\"},{\"question\":\"What are the two ways to loop over arrays in this lecture?\",\"answer\":\"One way uses an index-based for loop to iterate over part of the array and compute using the index (doubleArray[i]). The simpler way uses the enhanced for loop (for each double d in the array) to iterate over the entire array without an explicit index.\"}]","Lecture 11 - Arrays and ArrayLists - Introduction | PDF",33,[146,150],{"page_no":22,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/edd0e74a567fb3a943a0d3cf21c3dd0f.webp",983,1272,{"page_no":26,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/f58187510aa334b2abc567ca9dce859c.webp",982,1270,{"list":155,"token":11},[156,162,168,174,180,186,192,198,204,210],{"doc_id":157,"doc_title":158,"file_type":137,"home_preview_img_url":159,"slug":160,"view_count":117,"category_name":29,"create_tm":161},347081,"Java - Programming - Ninth Edition","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229910997878/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110379&Signature=1dDyp1C9IhPyi7AIx8KNuXgtVzg%3D","java-programming-ninth-edition",1790065180,{"doc_id":163,"doc_title":164,"file_type":137,"home_preview_img_url":165,"slug":166,"view_count":96,"category_name":29,"create_tm":167},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=1796110379&Signature=ExoeQRbbQFjplbs2YtRe1BX1Aoc%3D","implementing-an-arraylist-part-1-homeworkexam-announcements",1794016774,{"doc_id":169,"doc_title":170,"file_type":137,"home_preview_img_url":171,"slug":172,"view_count":33,"category_name":29,"create_tm":173},685785,"Arrays and Array Lists - Enhanced for Loop and 2D Arrays","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000208921/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110379&Signature=blKSh9tDhQ6LxUjpSZOm%2Fv8cfWs%3D","arrays-and-array-lists-enhanced-for-loop-and-2d-arrays",1794018474,{"doc_id":175,"doc_title":176,"file_type":137,"home_preview_img_url":177,"slug":178,"view_count":101,"category_name":29,"create_tm":179},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=1796110379&Signature=waobA3fq856FPbDs4CoPZKX8ESI%3D","array-lists-lecture-17-cs302-introduction-to-programming",1794018682,{"doc_id":181,"doc_title":182,"file_type":137,"home_preview_img_url":183,"slug":184,"view_count":96,"category_name":29,"create_tm":185},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=1796110379&Signature=mt3Qg%2BxnwWlRzb2ylVaa%2ByAMLuE%3D","numpy-array-chapter-11-informatics-practices",1794018711,{"doc_id":187,"doc_title":188,"file_type":137,"home_preview_img_url":189,"slug":190,"view_count":30,"category_name":29,"create_tm":191},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=1796110379&Signature=ODacdw0YKn6rjfZHkLJiJ1ZlkoQ%3D","arraylists-introduction-to-java-arraylist-and-generics",1794018675,{"doc_id":193,"doc_title":194,"file_type":137,"home_preview_img_url":195,"slug":196,"view_count":30,"category_name":29,"create_tm":197},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=1796110379&Signature=22ZW63quLgmY9vzw6sp3QP3tcdQ%3D","arrays-java-arrays-vs-python-lists-learn-how-to-declare-and-use-arrays-in-java",1794018478,{"doc_id":199,"doc_title":200,"file_type":137,"home_preview_img_url":201,"slug":202,"view_count":96,"category_name":29,"create_tm":203},685783,"Programming for GCSE Topic 6.1 - Lists, Arrays, and For Loops","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000208895/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110379&Signature=pE6%2F3CDR9VMy%2BJ7IkvRcA101S8s%3D","programming-for-gcse-topic-61-lists-arrays-and-for-loops",1794018470,{"doc_id":205,"doc_title":206,"file_type":137,"home_preview_img_url":207,"slug":208,"view_count":33,"category_name":29,"create_tm":209},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=1796110379&Signature=Gr39LAOFOm4C4JPH2L3%2BkNQeQqY%3D","unit06-1-arrays-arrays-in-memory-lecture-notes",1794446318,{"doc_id":211,"doc_title":212,"file_type":137,"home_preview_img_url":213,"slug":214,"view_count":96,"category_name":29,"create_tm":215},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=1796110379&Signature=0icdmbg7VDnabynDwGA73Hc2bbQ%3D","arraylist-in-java",1794016760]