tailieunhanh - Lecture Introduction to programming with Java - Chapter 10: Arrays and ArrayLists

Chapter 10: Arrays and ArrayLists. This chapter presents the following content: Array Basics, array declaration, array creation, array element initialization, array default values, array length property, partially filled arrays, copying an array, searching an array, sorting an array, selection sort. | Chapter 10 – Arrays and ArrayLists Array Basics Array Declaration Array Creation Array Element Initialization Array Default Values Array length Property Partially Filled Arrays Copying an Array Searching an Array Sorting an Array Selection Sort 1 Chapter 10 – Arrays and ArrayLists Two-Dimensional Arrays Arrays of Objects The ArrayList Class How to Create an ArrayList Object Adding Elements to an ArrayList Object How to Access an Element Within an ArrayList How to Update an ArrayList Object Additional ArrayList Methods Printing or Concatenating an ArrayList Storing Primitives in an ArrayList ArrayList Example Using Anonymous Objects and the For-Each Loop ArrayList Objects Versus Standard Arrays 2 Array Basics A class stores a group of related data, and it stores the methods that operate on that data. An array is a limited version of a class. Like a class, an array also stores a group of related data, but an array does not store methods. Another difference between an array and a class is that an array's data must all be of the same type. Here's a picture of an array that holds a list of phone numbers. Each of the five boxes is called an array element and each box stores one phone number. phoneList 8167412000 2024561111 7852963232 8008675309 0035318842133 first phone number last phone number 3 Array Basics A class uses dot notation to access one of its members. On the other hand, an array uses square brackets around an index to access one of its elements. The rightmost column shows how to access each of the 5 elements in the phoneList array. Note that the index values start at 0 instead of 1 and the last index value is one less than the number of elements in the array. index phoneList how to access each element 0 8167412000 phoneList[0] 1 2024561111 phoneList[1] 2 7852963232 phoneList[2] 3 8008675309 phoneList[3] 4 0035318842133 phoneList[4] 5 elements 4 Array Basics Here's how you can change the first phone number to 2013434: phoneList[0] = 2013434; . | Chapter 10 – Arrays and ArrayLists Array Basics Array Declaration Array Creation Array Element Initialization Array Default Values Array length Property Partially Filled Arrays Copying an Array Searching an Array Sorting an Array Selection Sort 1 Chapter 10 – Arrays and ArrayLists Two-Dimensional Arrays Arrays of Objects The ArrayList Class How to Create an ArrayList Object Adding Elements to an ArrayList Object How to Access an Element Within an ArrayList How to Update an ArrayList Object Additional ArrayList Methods Printing or Concatenating an ArrayList Storing Primitives in an ArrayList ArrayList Example Using Anonymous Objects and the For-Each Loop ArrayList Objects Versus Standard Arrays 2 Array Basics A class stores a group of related data, and it stores the methods that operate on that data. An array is a limited version of a class. Like a class, an array also stores a group of related data, but an array does not store methods. Another difference between an array and a

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.