chapter10_nn - Chapter 10 Arrays and ArrayLists 1 Array...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 10 – Arrays and  ArrayList s Array Basics Array Declaration Array Creation Array Element Initialization Array Default Values Array  length  Property Partially Filled Arrays Copying an Array Histograms Searching an Array Sorting an Array 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 10 – Arrays and  ArrayList s Selection Sort 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
Background image of page 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 speed-dial 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 speed-dial phone number last speed-dial phone number 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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
Background image of page 4
Array Basics Here's how you can change the first phone number to  2013434: phoneList[0] = 2013434; And here's how you can print the second phone  number: System.out.println(phoneList[1]); 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array Basics /************************************************************* * SpeedDialList.java * * This program creates a cell phone speed-dial phone number * list and prints the created list. *************************************************************/ import java.util.Scanner;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 78

chapter10_nn - Chapter 10 Arrays and ArrayLists 1 Array...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online