Knowee
Questions
Features
Study Tools

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]

Question

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]

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

Solution

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

Similar Questions

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, Cat, Horse]b.ArrayList: [Dog, Cat]c.ArrayList: [Dog]d.ArrayList: [Horse]

Write a JAVA program to create an Array List for objects of type String, and then several strings are added to it. Some of the elements are removed and the list is displayed again.Input-Output form:1.Addition2.Deletion3.Display4.Count number of elementsInput Choice: 1Enter element: AInput Choice: 1Enter element: BInput Choice: 1Enter element: CInput Choice: 2Enter element: CInput Choice: 3OutputàABInput Choice: 4Outputà2

import java.util.*;        public class Test {              public static void main(String[] args) {                     Map<Set<String>, List<String>> m = new HashMap<>();                     ArrayList<String> list1 = new ArrayList<>();                     list1.add("30");                     list1.add("40");                                    ArrayList<String> list2 = new ArrayList<String>();                     list2.add("35");                     list2.add("45");                     Set<String> set1 = new HashSet<>();                     set1.add("ravi");                     set1.add("ravi");                     m.put(set1,list1);                     m.put(set1,list2);                     System.out.println(m);              }         }

What is the result of this code?ArrayList<String> flowers = new ArrayList<>();flowers.add("daisy");flowers.add("rose");flowers.add("orchid");System.out.println(flowers.get(3));System.out.println(flowers.get(2));System.out.println(flowers.get(1));a.)<Exception error...>b.)orchidrosedaisyc.)321d.)daisyroseorchid

Sau khi thực hiện đoạn mã sau thì ArrayList chứa những phần tử nào? int x = 1; Integer y = 3; ArrayList a = new ArrayList(); a.add(3); a.add(9); a.add(5); a.remove(x); a.remove(y);

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.