Complete the getUniques and getDupes methods in the UniquesDupes class. Uniques are values that occur in the
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 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;
}
}
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill