Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HW 2, Due 21 1A An ArrayList of Integer type objects is called iList - Write an

ID: 3878861 • Letter: H

Question

HW 2, Due 21 1A An ArrayList of Integer type objects is called iList - Write an initialization statement for it - Write Java code to calculate the sum of all elements in it. (Hint: Use a - Suppose the content of iList is Integer objects of values What the list will be if Collections.reverse(iList); is executed? for-each loop.) 1 6 14 22 29 16 39 50 27 33 35 28 Start with the original list. What is the result if Collections.sort(iList); is executed? - Start with the original list. Are the results of following the same? Collections.reverse(iList) Collections.sort(iList); And Collections.sort(iList); Collections.reverse(iList) B. A list object wlist contains the words, in the order it is shown, print out You are going to trace the content of lists. Give the final content, and provide the this is not the droid you are looking for ArrayList result-new ArrayList() ; Collections.sort (wlist) for (String w: wlist) result.add (w) Collections.sort (wlist, new ByLength )) for (String w: wlist) result.add (w) for (String s: result) f if (s.startsWith("t")) result.remove (s) else System.out.println (s)) [Note: The first time sorting is by the alphabetical order. The second time sorting is by word length. See Example 1 above 2.] C. What would be the result of running following code (assuming the Card class is modified to be sortable)? cardHand ch = new CardHand (5) ; ch.add (new Card (5)) //add spade 5 ch. add (new Card (50) //add club J ch.add (new Card (14)) //add heart A ch.add (new Card (31)) //add diamond 5 ch.add (new Card (1)); //add spade A ch.sort); for (int io; i

Explanation / Answer

1A:
after Collections.reverse(iList) is executed; The list becomes
28 35 33 27 50 39 16 29 22 14 6 1

After Collections.Sort(iList) is executed; The list becomes
1 6 14 16 22 27 28 29 33 35 39 50

After sorting the iList, if we execute collections.reverse(iList); The list becomes
50 39 35 33 29 28 27 22 16 14 6 1