Page 1 of 1

Suppose we know how to combine students into an iterable class ArrayList. Fill in either y or n for the following questi

Posted: Fri May 20, 2022 5:10 pm
by answerhappygod
Suppose we know how to combine students into an iterable class
ArrayList.
Fill in either y or n for the following
questions.
Suppose We Know How To Combine Students Into An Iterable Class Arraylist Fill In Either Y Or N For The Following Questi 1
Suppose We Know How To Combine Students Into An Iterable Class Arraylist Fill In Either Y Or N For The Following Questi 1 (206.14 KiB) Viewed 66 times
Suppose we know how to combine students into an iterable class ArrayList. • First the enrolled students, in alpha order • Then the waitlisted students, in sign-up order • Then the hopeful students, in random order - uses Collections.shuffle() The function below will do the work and return iterable class ArrayList so that the enhanced for- loop will follow the order when we combined the students. private ArrayList<Students collectToList() { ArrayList<Student> all students = new ArrayListo (enrolled); all Students.addAll(waitList); ArrayList<Student> hopelist = new ArrayList<>Choping); // Randomize the hoping students. Collections. shuffle(hopelist); // Randomize the hoping students all Students.addAll(hopelist); return allStudents; } Then we can simplify the implementation of method iterator() as follows: public Iterator<Student> iterator {. return collectToList().iterator(); } Fill in either y or n for the following questions. (y/n) We can combine students into another iterable class TreeSet instead of ArrayList. The enhanced for-loop will still follow the order when we combined the students. That is, we could change collectToList as follows: private TreeSet<Students collectToList() { // combine students into TreeSet and return it } (y for yes, n for no) (y/n) We can combine students into another iterable class HashSet instead of ArrayList. The

(y/n) We can combine students into another iterable class HashSet instead of ArrayList. The enhanced for-loop will still follow the order when we combined the students. That is, we could change collectToList as follows: private HashSet<Student> collectToList() { // combine students into HashSet a nd return it } (y for yes, n for no)