| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard
Recursive ArrayList Filtering
< Prev
Next >

What is printed when the following program is executed?

import java.util.*;

public class Main {
    public static ArrayList<Integer> filterGreaterThan(ArrayList<Integer> list, int index, int threshold) {
        if(index >= list.size()) return new ArrayList<Integer>();
        ArrayList<Integer> result = filterGreaterThan(list, index + 1, threshold);
        if(list.get(index) > threshold) {
            result.add(0, list.get(index));
        }
        return result;
    }

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>(Arrays.asList(5, 12, 7, 20, 3));
        System.out.println(filterGreaterThan(list, 0, 10));
    }
}
A

[12]

B

[5, 12, 7, 20]

C

[20, 12]

D

[12, 20]

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy