Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 (Generics) Revise method removeDuplicates, so that is a generic version and can handle the code highlighted in BOLD. Attach your .java file with

Problem 1 (Generics) Revise method removeDuplicates, so that is a generic version and can handle the code highlighted in BOLD. Attach your .java file with the entire class Problem_1B and the updated version of the method.

import java.util.ArrayList;

import java.util.Arrays;

public class Problem_1B {

public static void main(String[] args) {

ArrayList list = new ArrayList();

list.add(14);

list.add(24);

list.add(14);

ArrayList newList = removeDuplicates(list);

System.out.print(newList);

System.out.println();

String[] names = {"bob", "susan", "bob"};

ArrayList stringList = new ArrayList<>(Arrays.asList(names));

stringList = removeDuplicatesGeneric(stringList);

System.out.print(stringList);

System.out.println();

}

public static ArrayList removeDuplicates(ArrayList list){

ArrayList result = new ArrayList();

for (Integer item: list) {

if (!result.contains(item))

result.add(item);

}

return result;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions