StudyFox

Arrays and ArrayLists

Open in StudyFox Free, no ads. Practice, track progress and quiz yourself in the app.

AP Computer Science A · Lesson 5 of 6 · 9 min read

// Remove all negative numbers
for (int i = list.size() - 1; i >= 0; i--) {
    if (list.get(i) < 0) {
        list.remove(i);
    }
}

Check your understanding

How do you get the number of elements in an array arr?

  1. arr.size()
  2. arr.length
  3. arr.length()
  4. arr.count
Show answer

Answer: B. Arrays use the field length with no parentheses. ArrayLists use size(); Strings use length().