Lists

Help Questions

AP Computer Science A › Lists

Questions 1 - 10
1

Which of the following is NOT a difference between the Array class and the ArrayList class in Java?

All of the other answer choices are differences between Arrays and ArrayLists in Java.

All of the other answer choices are differences between Arrays and ArrayLists in Java.

Arrays can store both primitives and Objects, while ArrayLists can only store Objects.

Arrays can store both primitives and Objects, while ArrayLists can only store Objects.

Arrays have a fixed size at creation, while ArrayLists can grow as needed.

Arrays have a fixed size at creation, while ArrayLists can grow as needed.

To find the number of spots in an Array, you append .length to the end of it. To find the number of spots in an ArrayList, you use the size() method.

To find the number of spots in an Array, you append .length to the end of it. To find the number of spots in an ArrayList, you use the size() method.

You have to manually add things to an Array by calling a command similar to my_array[some_number] = some_value. With ArrayLists, you use the add() method.

You have to manually add things to an Array by calling a command similar to my_array[some_number] = some_value. With ArrayLists, you use the add() method.

Explanation

In Java, Array is a fixed length data structure, while ArrayList is a variable length Collection Class (other Collection class members include HashMap and HashSet). This means that an Array cannot change its size once it's made; a whole new Array must be made. ArrayLists can change size at will.

Arrays can reference both primitives (like int) and types (like Integer). ArrayLists can only reference types, not primitives. Through a method called "Autoboxing", it can appear that an ArrayList stores a primitive, but what it really is doing is automatically masking the primitive with the type it's like so that it works with the ArrayList.

During the creation of an Array, the .length value is assigned, so whenever you append .length to the end of an array, you get the length (which will never change for the given Array). For ArrayLists, you use the .size() function, which returns the length of the ArrayList. Because the ArrayList size is variable, it is a function (which is why the parenthesis are there at the end).

Java provides the add() function for ArrayLists, which, as the name implies, adds the argument to the ArrayList. Arrays, on the other hand, do not have functions to add elements. To add something to an Array, you'd call something similar to this:

int[] my_array = new int[10];

my_array[0] = 5;

2

Which of the following is NOT a difference between the Array class and the ArrayList class in Java?

All of the other answer choices are differences between Arrays and ArrayLists in Java.

Arrays can store both primitives and Objects, while ArrayLists can only store Objects.

Arrays have a fixed size at creation, while ArrayLists can grow as needed.

To find the number of spots in an Array, you append .length to the end of it. To find the number of spots in an ArrayList, you use the size() method.

You have to manually add things to an Array by calling a command similar to my_array[some_number] = some_value. With ArrayLists, you use the add() method.

Explanation

In Java, Array is a fixed length data structure, while ArrayList is a variable length Collection Class (other Collection class members include HashMap and HashSet). This means that an Array cannot change its size once it's made; a whole new Array must be made. ArrayLists can change size at will.

Arrays can reference both primitives (like int) and types (like Integer). ArrayLists can only reference types, not primitives. Through a method called "Autoboxing", it can appear that an ArrayList stores a primitive, but what it really is doing is automatically masking the primitive with the type it's like so that it works with the ArrayList.

During the creation of an Array, the .length value is assigned, so whenever you append .length to the end of an array, you get the length (which will never change for the given Array). For ArrayLists, you use the .size() function, which returns the length of the ArrayList. Because the ArrayList size is variable, it is a function (which is why the parenthesis are there at the end).

Java provides the add() function for ArrayLists, which, as the name implies, adds the argument to the ArrayList. Arrays, on the other hand, do not have functions to add elements. To add something to an Array, you'd call something similar to this:

int[] my_array = new int[10];

my_array[0] = 5;

3

Which of the following is NOT a difference between the Array class and the ArrayList class in Java?

All of the other answer choices are differences between Arrays and ArrayLists in Java.

Arrays can store both primitives and Objects, while ArrayLists can only store Objects.

Arrays have a fixed size at creation, while ArrayLists can grow as needed.

To find the number of spots in an Array, you append .length to the end of it. To find the number of spots in an ArrayList, you use the size() method.

You have to manually add things to an Array by calling a command similar to my_array[some_number] = some_value. With ArrayLists, you use the add() method.

Explanation

In Java, Array is a fixed length data structure, while ArrayList is a variable length Collection Class (other Collection class members include HashMap and HashSet). This means that an Array cannot change its size once it's made; a whole new Array must be made. ArrayLists can change size at will.

Arrays can reference both primitives (like int) and types (like Integer). ArrayLists can only reference types, not primitives. Through a method called "Autoboxing", it can appear that an ArrayList stores a primitive, but what it really is doing is automatically masking the primitive with the type it's like so that it works with the ArrayList.

During the creation of an Array, the .length value is assigned, so whenever you append .length to the end of an array, you get the length (which will never change for the given Array). For ArrayLists, you use the .size() function, which returns the length of the ArrayList. Because the ArrayList size is variable, it is a function (which is why the parenthesis are there at the end).

Java provides the add() function for ArrayLists, which, as the name implies, adds the argument to the ArrayList. Arrays, on the other hand, do not have functions to add elements. To add something to an Array, you'd call something similar to this:

int[] my_array = new int[10];

my_array[0] = 5;

4

Which of the following is NOT a difference between the Array class and the ArrayList class in Java?

All of the other answer choices are differences between Arrays and ArrayLists in Java.

Arrays can store both primitives and Objects, while ArrayLists can only store Objects.

Arrays have a fixed size at creation, while ArrayLists can grow as needed.

To find the number of spots in an Array, you append .length to the end of it. To find the number of spots in an ArrayList, you use the size() method.

You have to manually add things to an Array by calling a command similar to my_array[some_number] = some_value. With ArrayLists, you use the add() method.

Explanation

In Java, Array is a fixed length data structure, while ArrayList is a variable length Collection Class (other Collection class members include HashMap and HashSet). This means that an Array cannot change its size once it's made; a whole new Array must be made. ArrayLists can change size at will.

Arrays can reference both primitives (like int) and types (like Integer). ArrayLists can only reference types, not primitives. Through a method called "Autoboxing", it can appear that an ArrayList stores a primitive, but what it really is doing is automatically masking the primitive with the type it's like so that it works with the ArrayList.

During the creation of an Array, the .length value is assigned, so whenever you append .length to the end of an array, you get the length (which will never change for the given Array). For ArrayLists, you use the .size() function, which returns the length of the ArrayList. Because the ArrayList size is variable, it is a function (which is why the parenthesis are there at the end).

Java provides the add() function for ArrayLists, which, as the name implies, adds the argument to the ArrayList. Arrays, on the other hand, do not have functions to add elements. To add something to an Array, you'd call something similar to this:

int[] my_array = new int[10];

my_array[0] = 5;

5

Which of the following is NOT a difference between the Array class and the ArrayList class in Java?

All of the other answer choices are differences between Arrays and ArrayLists in Java.

Arrays can store both primitives and Objects, while ArrayLists can only store Objects.

Arrays have a fixed size at creation, while ArrayLists can grow as needed.

To find the number of spots in an Array, you append .length to the end of it. To find the number of spots in an ArrayList, you use the size() method.

You have to manually add things to an Array by calling a command similar to my_array[some_number] = some_value. With ArrayLists, you use the add() method.

Explanation

In Java, Array is a fixed length data structure, while ArrayList is a variable length Collection Class (other Collection class members include HashMap and HashSet). This means that an Array cannot change its size once it's made; a whole new Array must be made. ArrayLists can change size at will.

Arrays can reference both primitives (like int) and types (like Integer). ArrayLists can only reference types, not primitives. Through a method called "Autoboxing", it can appear that an ArrayList stores a primitive, but what it really is doing is automatically masking the primitive with the type it's like so that it works with the ArrayList.

During the creation of an Array, the .length value is assigned, so whenever you append .length to the end of an array, you get the length (which will never change for the given Array). For ArrayLists, you use the .size() function, which returns the length of the ArrayList. Because the ArrayList size is variable, it is a function (which is why the parenthesis are there at the end).

Java provides the add() function for ArrayLists, which, as the name implies, adds the argument to the ArrayList. Arrays, on the other hand, do not have functions to add elements. To add something to an Array, you'd call something similar to this:

int[] my_array = new int[10];

my_array[0] = 5;

6

Consider the following code:

public static class Circle {

private double radius;

public Circle(double r) {

radius = r;

}

public double getArea() {

return radius * radius * Math.PI;

}

}

public static void main(String\[\] args) {

ArrayList circles = new ArrayList();

for(int i = 0; i < 10; i++) {

circles.add(new Circle(i + 4 * 2));

}

}

Which of the following represents code for iterating through the list circles in order to output the areas of the circles contained therein?

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles.get(i).getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles.get(i).getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.length; i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.length; i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].get().getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].get().getArea());

}

for(int i = 0; i < circles.size; i++) {

System.out.println(circles.get()\[i\].getArea());

}

for(int i = 0; i < circles.size; i++) {

System.out.println(circles.get()\[i\].getArea());

}

Explanation

In the answers, there are only two issues to consider. On the one hand, look at the loop control statement. It is some variant on:

circle.size()

and

circles.length

For the List types, you need to use the method size(), not length (which you use for arrays). Likewise, one way to extract elements from the ArrayList type is to use the .get method. You must use this and not the brackets \[\] that you use for arrays.

7

Consider the following code:

public static class Circle {

private double radius;

public Circle(double r) {

radius = r;

}

public double getArea() {

return radius * radius * Math.PI;

}

}

public static void main(String\[\] args) {

ArrayList circles = new ArrayList();

for(int i = 0; i < 10; i++) {

circles.add(new Circle(i + 4 * 2));

}

}

Which of the following represents code for iterating through the list circles in order to output the areas of the circles contained therein?

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles.get(i).getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.length; i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].get().getArea());

}

for(int i = 0; i < circles.size; i++) {

System.out.println(circles.get()\[i\].getArea());

}

Explanation

In the answers, there are only two issues to consider. On the one hand, look at the loop control statement. It is some variant on:

circle.size()

and

circles.length

For the List types, you need to use the method size(), not length (which you use for arrays). Likewise, one way to extract elements from the ArrayList type is to use the .get method. You must use this and not the brackets \[\] that you use for arrays.

8

Consider the following code:

public static class Circle {

private double radius;

public Circle(double r) {

radius = r;

}

public double getArea() {

return radius * radius * Math.PI;

}

}

public static void main(String\[\] args) {

ArrayList circles = new ArrayList();

for(int i = 0; i < 10; i++) {

circles.add(new Circle(i + 4 * 2));

}

}

Which of the following represents code for iterating through the list circles in order to output the areas of the circles contained therein?

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles.get(i).getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.length; i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].get().getArea());

}

for(int i = 0; i < circles.size; i++) {

System.out.println(circles.get()\[i\].getArea());

}

Explanation

In the answers, there are only two issues to consider. On the one hand, look at the loop control statement. It is some variant on:

circle.size()

and

circles.length

For the List types, you need to use the method size(), not length (which you use for arrays). Likewise, one way to extract elements from the ArrayList type is to use the .get method. You must use this and not the brackets \[\] that you use for arrays.

9

Consider the following code:

public static class Circle {

private double radius;

public Circle(double r) {

radius = r;

}

public double getArea() {

return radius * radius * Math.PI;

}

}

public static void main(String\[\] args) {

ArrayList circles = new ArrayList();

for(int i = 0; i < 10; i++) {

circles.add(new Circle(i + 4 * 2));

}

}

Which of the following represents code for iterating through the list circles in order to output the areas of the circles contained therein?

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles.get(i).getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.length; i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].get().getArea());

}

for(int i = 0; i < circles.size; i++) {

System.out.println(circles.get()\[i\].getArea());

}

Explanation

In the answers, there are only two issues to consider. On the one hand, look at the loop control statement. It is some variant on:

circle.size()

and

circles.length

For the List types, you need to use the method size(), not length (which you use for arrays). Likewise, one way to extract elements from the ArrayList type is to use the .get method. You must use this and not the brackets \[\] that you use for arrays.

10

Consider the following code:

public static class Circle {

private double radius;

public Circle(double r) {

radius = r;

}

public double getArea() {

return radius * radius * Math.PI;

}

}

public static void main(String\[\] args) {

ArrayList circles = new ArrayList();

for(int i = 0; i < 10; i++) {

circles.add(new Circle(i + 4 * 2));

}

}

Which of the following represents code for iterating through the list circles in order to output the areas of the circles contained therein?

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles.get(i).getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.length; i++) {

System.out.println(circles\[i\].getArea());

}

for(int i = 0; i < circles.size(); i++) {

System.out.println(circles\[i\].get().getArea());

}

for(int i = 0; i < circles.size; i++) {

System.out.println(circles.get()\[i\].getArea());

}

Explanation

In the answers, there are only two issues to consider. On the one hand, look at the loop control statement. It is some variant on:

circle.size()

and

circles.length

For the List types, you need to use the method size(), not length (which you use for arrays). Likewise, one way to extract elements from the ArrayList type is to use the .get method. You must use this and not the brackets \[\] that you use for arrays.

Page 1 of 3
Return to subject