[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685795-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-685795-en":130,"doc-similar-685795":152},{"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","tutorial-arrays-and-arraylist-introduction-and-examples","Tutorial - Arrays and ArrayList - Introduction and Examples","","Tutorial material focused on arrays and Java’s ArrayList concepts, using slide-style notes and examples. It explains what array elements and element types are, how arrays are declared and instantiated, and how to iterate through arrays using an enhanced for loop. The content covers array bounds checking, common off-by-one mistakes, and includes sample code for processing numbers in normal and reverse order. It also demonstrates string length usage and initializer lists, plus arrays of object references with null initial values.",{"@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/tutorial-arrays-and-arraylist-introduction-and-examples/685795/",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/tutorial-arrays-and-arraylist-introduction-and-examples/685795.png","ImageObject",300,407,{"name":42,"@type":43},"McQueen","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},"What is an array element and what is the element type in Java?","Question",{"text":62,"@type":63},"An array holds multiple values called array elements. The element type describes the type of each element and can be a primitive type or an object reference.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do you declare and instantiate an array in Java?",{"text":67,"@type":63},"Declare the array type and variable, then instantiate it using new with a size, e.g., int[] scores = new int[10]; The array type does not specify its size, but each created array object has a specific size.",{"name":69,"@type":60,"acceptedAnswer":70},"Why do bounds checking and off-by-one errors matter for arrays?",{"text":71,"@type":63},"Arrays have a fixed size, and valid indices must be in the range 0 to N-1. The Java runtime throws ArrayIndexOutOfBoundsException when an index is out of range, and off-by-one mistakes often occur when using incorrect loop limits.","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},685795,1794018675,{"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":117,"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":102,"preview_page_count":26,"preview_urls":143},5909890329169,"https://ap-avatar.wpscdn.com/davatar_9964176cb1d06d4a9deccf72a44ae3dc","5. Arrays and ArrayList  \nFollowing slides are borrowed from the book’s free supplement Presentation Slides, [http://duke.csc.villanova.edu/jss1/](http://duke.csc.villanova.edu/jss1/)  \nArrays  \n• The values held in an array are called array elements  \n• An array stores multiple values of the same type – the element type  \n• The element type can be a primitive type or an object reference  \n• Therefore, we can create an array of integers, an array of characters, an array of String objects, an array of Coin objects, etc .  \n• In Java, the array itself is an object that must be instantiated  \n© 2004 Pearson Addison-Wesley. All rights reserved 1-2  \nDeclaring Arrays  \n• The scores array could be declared as  \n•  \n•  \n•  \nfollows:  \nscores  \nint[] scores = new int[10];  \nThe type of the variable scores is int[](an array of integers)  \nNote that the array type does not specify its size, but each object of that type has a specific size  \nThe reference variable scores is set to anew array object that can hold 10 integers  \n\n| 79 |\n| --- |\n| 87 |\n| 94 |\n| 82 |\n| 67 |\n| 98 |\n| 87 |\n| 81 |\n| 74 |\n| 91 |\n\n© 2004 Pearson Addison-Wesley. All rights reserved 1-3  \nUsing Arrays  \n• The iterator version of the for loop can be used when processing array elements  \nfor (int score : scores)  \nSystem.out.println (score);  \n• This is only appropriate when processing all array elements from top (lowest index) to bottom (highest index)  \n• Each array object has a public constant called length that stores the size of the array. Note that length holds the number of elements, not the largest index  \n© 2004 Pearson Addison-Wesley. All rights reserved 1-4  \nBounds Checking  \n• Once an array is created, it has a fixed size  \n• An index used in an array reference must specify a valid element. That is, the index value must be in range 0 to N-1  \n• The Java interpreter throws an ArrayIndexOutOfBoundsException if an array index is out of bounds (called automatic bounds checking)  \n• It’s common to introduce off-by-one errors when using arrays problem  \nint[] scores = new int[10] ;   \nfor (int index=0; index \u003C= 100 ; index++)  \ncodes[index] = index*50 + epsilon;  \n© 2004 Pearson Addison-Wesley. All rights reserved 1-5  \nExample: [ReverseOrder.java](ReverseOrder.java)  \ndouble[] numbers = new double[10];  \nfor (int index = 0; index \u003C numbers .length; index++) {  \nSystem.out.print (\"Enter number \" + (index+1) + \": \");  \nnumbers[index] = scan .nextDouble();  \n}  \nSystem.out.println (\"The numbers in reverse order:\");  \nfor (int index = numbers .length-1; index >= 0; index--)  \nSystem.out.print (numbers[index] + \" \");  \n}  \nThere is a shortcut link in  \n[http://www.cs.mcgill.ca/](http://www.cs.mcgill.ca/) ~jli127  \n© 2004 Pearson Addison-Wesley. All rights reserved 1-6  \nExample: [LetterCount.java](LetterCount.java)  \n• Length of a String line is line.length(), where array upper[] is upper .length . The difference means ??  \n• What’s this upper[current- 'A']++; and lower[current- 'a']++;  \n• Q: the \\# of appearance of letter ‘B’, ‘c’ are stored in where? upper[x] or lower[y] ?  \n• Q: what’s the result for string ‘aBcD’ ?  \nThere is a shortcut link in  \n[http://www.cs.mcgill.ca/](http://www.cs.mcgill.ca/) ~jli127  \n© 2004 Pearson Addison-Wesley. All rights reserved 1-7  \nInitializer Lists  \n• An initializer list can be used to instantiate and fill an array in one step . But it can be used only in the array declaration  \n• The values are delimited by braces and separated by commas  \n• Note that when an initializer list is used:  \n􀀁 the new operator is not used  \n􀀁 no size value is specified,(size is determined by the number of items in the initializer list)  \n• Examples:  \nint[] units = {147, 323, 89, 933, 540};  \nchar[] letterGrades = {'A', 'B', 'C', 'D', ’F'};  \n© 2004 Pearson Addison-Wesley. All rights reserved 1-8  \nArrays of Objects  \n• The elements of an array can be object references  \n• The following declaration reserves space to store 5 references to String o","cbCaidm46xFbzpF4","https://ap.wps.com/l/cbCaidm46xFbzpF4","pdf",334112,"English","# Arrays and ArrayList\n## Arrays basics\n## Declaring and using arrays\n## Bounds checking and off-by-one errors\n## Examples: iteration, reverse order, string length\n## Initializer lists and arrays of objects","[{\"question\":\"What is an array element and what is the element type in Java?\",\"answer\":\"An array holds multiple values called array elements. The element type describes the type of each element and can be a primitive type or an object reference.\"},{\"question\":\"How do you declare and instantiate an array in Java?\",\"answer\":\"Declare the array type and variable, then instantiate it using new with a size, e.g., int[] scores = new int[10]; The array type does not specify its size, but each created array object has a specific size.\"},{\"question\":\"Why do bounds checking and off-by-one errors matter for arrays?\",\"answer\":\"Arrays have a fixed size, and valid indices must be in the range 0 to N-1. The Java runtime throws ArrayIndexOutOfBoundsException when an index is out of range, and off-by-one mistakes often occur when using incorrect loop limits.\"}]","Tutorial - Arrays and ArrayList - Introduction and Examples | PDF",[144,148],{"page_no":22,"url":145,"width":146,"height":147},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/5d5f7afd3fbdf9af322e0d2921b6fd76.webp",983,737,{"page_no":26,"url":149,"width":150,"height":151},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/5bd24c6e6bc50ce31a34b7bbe9f5569a.webp",982,736,{"list":153,"token":11},[154,159,165,171,177,183,189,195,201,207],{"doc_id":155,"doc_title":156,"file_type":137,"home_preview_img_url":157,"slug":158,"view_count":30,"category_name":29,"create_tm":79},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=1796110859&Signature=afzFfUNRTcKpp5i3OgOt5yhe7uM%3D","arraylists-introduction-to-java-arraylist-and-generics",{"doc_id":160,"doc_title":161,"file_type":137,"home_preview_img_url":162,"slug":163,"view_count":96,"category_name":29,"create_tm":164},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=1796110859&Signature=bp4MO1TQtsNZ4o%2F9SX993pHI%2FV8%3D","implementing-an-arraylist-part-1-homeworkexam-announcements",1794016774,{"doc_id":166,"doc_title":167,"file_type":137,"home_preview_img_url":168,"slug":169,"view_count":33,"category_name":29,"create_tm":170},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=1796110859&Signature=Zu%2B8lCD7Xg68%2BF0oqMwWrnprcyo%3D","list-and-arraylist-java-data-structure-overview",1794016763,{"doc_id":172,"doc_title":173,"file_type":137,"home_preview_img_url":174,"slug":175,"view_count":115,"category_name":29,"create_tm":176},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=1796110859&Signature=N8yFWckLvjMwLA0gtSSlAhc8a2g%3D","core-java-volume-i-fundamentals-twelfth-edition",1794018671,{"doc_id":178,"doc_title":179,"file_type":137,"home_preview_img_url":180,"slug":181,"view_count":30,"category_name":29,"create_tm":182},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=1796110859&Signature=uywX0db7ngOt%2FzHz0ZuOgAAGaDs%3D","introduction-to-linked-lists-part-15-121",1795006735,{"doc_id":184,"doc_title":185,"file_type":137,"home_preview_img_url":186,"slug":187,"view_count":33,"category_name":29,"create_tm":188},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=1796110859&Signature=N2cvZz91QnITg75Fa2NBgBMp5%2F0%3D","arrays-and-array-lists-enhanced-for-loop-and-2d-arrays",1794018474,{"doc_id":190,"doc_title":191,"file_type":137,"home_preview_img_url":192,"slug":193,"view_count":96,"category_name":29,"create_tm":194},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=1796110859&Signature=sxf2CV01bqXn5hQzys2WXjlvsYw%3D","arraylist-in-java",1794016760,{"doc_id":196,"doc_title":197,"file_type":137,"home_preview_img_url":198,"slug":199,"view_count":33,"category_name":29,"create_tm":200},697965,"Arrays Made Easy - An Introduction to Arrays and Array Processing - SUGI 30 Tutorials","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146275/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=vsLldAzxcyTCwEu%2BGnASZJXnFxQ%3D","arrays-made-easy-an-introduction-to-arrays-and-array-processing-sugi-30-tutorials",1794446535,{"doc_id":202,"doc_title":203,"file_type":137,"home_preview_img_url":204,"slug":205,"view_count":33,"category_name":29,"create_tm":206},685683,"JSON - Quick Guide - Overview - Syntax - Datatypes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999686685/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=7kD1W1l6iqTOu%2FUWPS5hxUQC7uA%3D","json-quick-guide-overview-syntax-datatypes",1794016574,{"doc_id":208,"doc_title":209,"file_type":137,"home_preview_img_url":210,"slug":211,"view_count":33,"category_name":29,"create_tm":212},732876,"Lecture 10 - Linked Lists - Lecture notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031413512/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110859&Signature=mpba9B%2FNFzkimXGr%2BTxKJorzMC4%3D","lecture-10-linked-lists-lecture-notes",1795382672]