Question
Complete the getUniques and getDupes methods in the UniquesDupes class. Uniques are values that occur in the original list at least once. Duplicates are values
Complete the getUniques and getDupes methods in the UniquesDupes class. Uniques are values that occur in the original list at least once. Duplicates are values that occur in the original list more than once.
Use the String split method to seperate the string. input.split(" ") returns a string array where the original input string has been seperated by spaces. For example, "a b cd e".split(" ") returns a string array containing {"a", "b", "cd", "e"}.
Sample Output
Original : a b c d e f a c e a e
Uniques : [a, b, c, d, e, f]
Duplicates : [a, c, e]
Main.java
import java.util.*;
class Main {
public static void main(String[] args) {
String[] str = new String[3];
str[0] = "a b c d e f a c e a e";
str[1] = "one two three one two three six seven one two";
str[2] = "1 2 3 4 5 1 3 4 5 1 3 4 5 6";
for (int i = 0; i < str.length; i++) {
System.out.println("Original : " + str[i]);
System.out.println("Uniques : " + UniquesDupes.getUniques(str[i]));
System.out.println("Duplicates : " + UniquesDupes.getDupes(str[i]));
System.out.println();
}
}
}
UniquesDupes.java
import java.util.*;
public class UniquesDupes {
/**
* Returns a Set containing the unique values in the given input string. Uniques
* are values that occur in the original list at least once.
*/
public static Set getUniques(String input) {
return null;
}
/**
* Returns a Set containing the unique duplicate values in the given input
* string. Duplicates are values that occur in the original list more than once.
* Note: The add method for the Set class returns false if the value already
* exists in a Set.
*/
public static Set getDupes(String input) {
return null;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
import javautil public class UniquesDupes Returns a Set containing the uniq...Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started