study guides for every class
that actually explain what's on your next test
Array.size()
from class:
AP Computer Science A
Definition
In this context, `array.size()` returns the number of elements currently stored in the ArrayList called 'array'.
"Array.size()" also found in:
Practice Questions (4)
- What does the following code do?
public static boolean codeBlock(ArrayList<Integer> array) {
for (int i = 0; i < array.size() - 1; i++) {
for (int j = i + 1; j < array.size(); j++) {
if (array.get(j) == array.get(i)) {
return true;
}
}
}
return false;
}
- What does the following code do?
public static ArrayList<Integer> codeBlock(ArrayList<Integer> array) {
int lastItem = array.get(array.size()- 1)
for (int i = array.size() - 1; i > 0; i--) {
array.set(i, array.get(i-1));
}
array.set(0, lastItem);
return array;
}
- What is returned by the following code if the ArrayList [5, 6, 3, 10] is passed in?
public static int codeBlock(ArrayList<Integer> array) {
int x = 0;
for (int y: array) {
x += y;
}
return (double) x / (array.size());
}
- After calling the following method on the ArrayList [5, 1, 2, 3], what are its elements?
public static void codeBlock(ArrayList<Integer> array) {
for (int i = 0; i < array.size(); i++) {
array.set(i, array.get(i) * array.get(i));
}
}
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.