Knowee
Questions
Features
Study Tools

11. public static Iterator reverse(List list) {12. Collections.reverse(list);13. return list.iterator();14. }15. public static void main(String[] args) {16. List list = new ArrayList();17. list.add(" 1"); list.add("2"); list.add("3");18. for (Object obj: reverse(list))19. System.out.print(obj + ",");20. }'What is the result? (Choose one.)a. 3, 2, 1,b. 1, 2, 3,c. Compilation fails.d. The code runs with no output.e. An exception is thrown at runtime.

Question

  1. public static Iterator reverse(List list) {12. Collections.reverse(list);13. return list.iterator();14. }15. public static void main(String[] args) {16. List list = new ArrayList();17. list.add(" 1"); list.add("2"); list.add("3");18. for (Object obj: reverse(list))19. System.out.print(obj + ",");20. }'What is the result? (Choose one.)a. 3, 2, 1,b. 1, 2, 3,c. Compilation fails.d. The code runs with no output.e. An exception is thrown at runtime.
...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The result of the given code is: a. 3, 2, 1.

Similar Questions

Analyze the following code:  public class Test {   public static void main(String[] args) {     int[] oldList = {1, 2, 3, 4, 5};     reverse(oldList);     for (int i = 0; i < oldList.length; i++)       System.out.print(oldList[i] + " ");   }    public static void reverse(int[] list) {     int[] newList = new int[list.length];      for (int i = 0; i < list.length; i++)       newList[i] = list[list.length - 1 - i];      list = newList;   } } Group of answer choicesThe program displays 1 2 3 4 5.The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.The program displays 5 4 3 2 1.The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.

What is the output of the following code?import java.util.*;public class Main { public static void main(String[] args) { List list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); Iterator iterator = list.iterator(); while (iterator.hasNext()) { Integer value = iterator.next(); if (value == 2) { iterator.remove(); } } System.out.println(list); }}a)[2, 3]b)[3, 2, 1]c)[1, 2, 3]d)[1, 3]

Write a java method to reverse the elements of an array using recursion. Your method should take an array as an input parameter and return reverse the array

What is the output of the following program:import java.util.*;class TestJavaCollection1 { public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); // Creating arraylist list.add("Apple"); // Adding object in arraylist list.add("Orange"); list.add("Strawberry"); list.add("Apple"); // Traversing list through Iterator Iterator itr = list.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } }}

You are using the following code snippet in your application when working with Lists in Java.CodeList list = Arrays.asList(1, 2, 3, 4;list.forEach(i -> {i *= 2; System.out.print(i)});What will be the result of executing the code snippet?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.