AP Computer Science A Unit 7 Progress Check: MCQE Exam
Consider the following statement, which is intended to create an ArrayList named a to store only elements of type Thing. Assume that the Thing class has been properly defined and includes a no-parameter constructor.
ArrayList<Thing> a = /* missing code */;
Which of the following can be used to replace /* missing code */ so that the statement works as intended? - Answer -B. new ArrayList<Thing>()
Consider the following statement, which is intended to create an ArrayList named numbers that can be used to store Integer values.
ArrayList<Integer> numbers = /* missing code */;
Which of the following can be used to replace /* missing code */ so that the statement works as intended?
new ArrayList()
new ArrayList<Integer>
new ArrayList<Integer>() - Answer -C. I and III only
Consider the following statement, which is intended to create an ArrayList named arrList
to store elements only of type String.
/* missing code */ = new ArrayList<String>();
Which of the following can be used to replace /* missing code */ so that the statement works as intended? - Answer -E. ArrayList<String> arrList
Consider the following code segment.
ArrayList<Integer> nums = new ArrayList<>();
nums.add(3);
nums.add(2);
nums.add(1);
nums.add(0);
nums.add(0, 4);
nums.set(3, 2);
nums.remove(3);
nums.add(2, 0);
Which of the following represents the contents of nums after the code segment has been executed? - Answer -D. [4, 3, 0, 2, 0] Consider the following code segment.
ArrayList<String> syllables = new ArrayList<String>();
syllables.add("LA");
syllables.add(0, "DI");
syllables.set(1, "TU");
syllables.add("DA");
syllables.add(2, syllables.get(0));
syllables.remove(1);
System.out.println(syllables.toString());
What is printed as a result of executing the code segment? - Answer -B. [DI, DI, DA]
Consider the following code segment.
ArrayList<Integer> vals = new ArrayList<Integer>();
vals.add(vals.size(), vals.size());
vals.add(vals.size() - 1, vals.size() + 1);
vals.add(vals.size() - 2, vals.size() + 2);
System.out.println(vals.toString());
What is printed as a result of executing the code segment? - Answer -E. [4, 2, 0]
Consider the following code segment.
ArrayList<Integer> myList = new ArrayList();
for (int i = 0; i < 4; i++)
{
myList.add(i + 1);
}
for (int i = 0; i < 4; i++)
{
if (i % 2 == 0)
{
System.out.print(myList.get(i) + " ");
}
}
What output is produced as a result of executing the code segment? - Answer -D. 1 3
Consider the following code segment.
ArrayList<String> words = new ArrayList<String>();
words.add("mat");
words.add("new");
words.add("open");
words.add("pet");
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller millyphilip. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $11.49. You're not tied to anything after your purchase.