zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

ArrayList in AP Computer Science A

Question 1
college-boardComputer Science AAPExam Style
1 mark

Given ArrayList<String> words = new ArrayList<>(Arrays.asList("apple","banana","cherry","date"));, which modification would reverse their order to [“date”,”cherry”,”banana”,”apple”] using minimal calls to ArrayList methods?

Question 2
college-boardComputer Science AAPExam Style
1 mark

When trying to retrieve an element from an ArrayList at a certain index, which exception is thrown if the index is out of bounds?

Question 3
college-boardComputer Science AAPExam Style
1 mark

What does the get(int index) method of an ArrayList return?

Question 4
college-boardComputer Science AAPExam Style
1 mark

After executing ArrayList<String> colors = new ArrayList<>(Arrays.asList("red", "green", "blue")); , what does colors.get(1) return?

Question 5
college-boardComputer Science AAPExam Style
1 mark

Given an abstract class 'Shape' with subclasses 'Circle', 'Rectangle', etc., if you have an ArrayList shapes where elements need casting before specific methods can be called, how do you avoid ClassCastException?

Question 6
college-boardComputer Science AAPExam Style
1 mark

How can you determine if an ArrayList named “inventory” contains a specific item known as “widget”?

Question 7
college-boardComputer Science AAPExam Style
1 mark

After executing this line of code on an existing populated ArrayList<Double> doublesList, what will be its effect?:

java
doublesList.set(doublesList.indexOf(Collections.max(doublesList)), Math.PI);
Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
college-boardComputer Science AAPExam Style
1 mark

For given code snippet 'List doubles=new Random.storage.DoubleStream.limit10.mapToObj(d->Math.round (D*100)/100d.collect(CollectorstoList()));' which alternative creates similar List where each double truncated two decimal places?

Question 9
college-boardComputer Science AAPExam Style
1 mark

Why are helper methods useful in a class that implements complex algorithms?

Question 10
college-boardComputer Science AAPExam Style
1 mark

How do you retrieve an element from an ArrayList at a given position?