Knowee
Questions
Features
Study Tools

What is the output of the following program:import java.util.ArrayList;class Main { public static void main(String[] args){ ArrayList<String> animals = new ArrayList<>(); animals.add("Dog"); animals.add("Cat"); animals.add("Horse"); animals.remove(2); System.out.println("ArrayList: " + animals); }}Select one:a.ArrayList: [Dog]b.ArrayList: [Dog, Cat]c.ArrayList: [Dog, Cat, Horse]d.ArrayList: [Horse]

Question

What is the output of the following program:import java.util.ArrayList;class Main { public static void main(String[] args){ ArrayList<String> animals = new ArrayList<>(); animals.add("Dog"); animals.add("Cat"); animals.add("Horse"); animals.remove(2); System.out.println("ArrayList: " + animals); }}Select one:a.ArrayList: [Dog]b.ArrayList: [Dog, Cat]c.ArrayList: [Dog, Cat, Horse]d.ArrayList: [Horse]

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is b. ArrayList: [Dog, Cat]

Similar Questions

import java.util.ArrayList;class Main { public static void main(String[] args){ ArrayList<String> animals = new ArrayList<>(); animals.add("Dog"); animals.add("Cat"); animals.add("Horse"); animals.remove(2); System.out.println("ArrayList: " + animals); }}Select one:a.ArrayList: [Dog, Cat, Horse]b.ArrayList: [Horse]c.ArrayList: [Dog]d.ArrayList: [Dog, Cat]

What is the output of the following code snippet?ArrayList<String> fruits = new ArrayList<>();fruits.add("Apple");fruits.add("Orange");fruits.add("Banana");System.out.println(fruits.size());Question 17Answera.1b.2c.3d.0

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]

What is the output of the following code snippet?ArrayList<Integer> numbers = new ArrayList<>();numbers.add(1);numbers.add(2);numbers.add(3);System.out.println(numbers.get(2));

What is the output of the following program:import java.util.*;public class LinkedList2 { public static void main(String args[]) { LinkedList<String> ll = new LinkedList<String>(); ll.add("Cat"); ll.add("Dog"); ll.add("Rabbit"); ll.remove(); System.out.println(ll.size()); Iterator i = ll.descendingIterator(); while (i.hasNext()) { System.out.println(i.next()); } }}Select one:a.2DogRabbitb.2DogCatc.2CatRabbitd.2CatDog

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.