Lesson Purpose and Objectives

  • Understand how arrays work and how to use them
  • Understand advantages and disadvantages in Java
  • Apply understanding of arrays to problems

AP Classroom Requirements

  • 3.D - Write program code to create, traverse, and manipulate elements in 1D array or ArrayList objects.
  • 6.1 - Array Creation and Access
  • 6.2 - Traversing Arrays
  • 6.3 - Enhanced for Loop for Arrays
  • 6.4 - Developing Algorithms Using Arrays

Slideshow Embed

Hacks / Homework

Write a class called ArrayMethods that contains two methods that utilize/manipulate an array. You may choose 2 of the 4 options below to complete. Extra credit for doing all 4 options. Make sure to show test cases for all of the options you choose.

Options for hacks (Pick two):

  • Swap the first and last element in the array
  • Replace all even elements with 0
  • Return true if the array is currently sorted in increasing order
  • Return true if the array contains duplicate elements
// Write array methods for the Array Methods class below out of the options given above.
public class ArrayMethods {
    private int[] values;
}