reate a class called RemoveDuplicates that takes a LinkedList of colors (represented using Strings) and returns a HashSet of just the unique colors in the list. In addition, your class should keep track of the number of duplicates that were discovered and removed.
create a class called RemoveDuplicates that takes a LinkedList of colors (represented using Strings) and returns a HashSet of just the unique colors in the list. In addition, your class should keep track of the number of duplicates that were discovered and removed.
import java.util.*;
public class Main
{
public static void main(String[] args)
{
LinkedList<String> v = new LinkedList<String>();
v.add("red");
v.add("blue");
v.add("green");
v.add("blue");
v.add("yellow");
v.add("orange");
v.add("green");
v.add("green");
v.add("purple");
v.add("red");
RemoveDuplicates remover = new RemoveDuplicates();
HashSet<String> colors = remover.removeDuplicates(v);
System.out.println(colors);
System.out.println("Duplicate count = " + remover.getDuplicateCount());
}
}
output
[red, orange, green, blue, yellow, purple]
Duplicate count = 4
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images