Are you taking CLEP classes? Try clep.ai
| 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

Mark
< 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

[20, 12]

C

[12, 20]

D

[5, 12, 7, 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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|