Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- import java.util.*;
- import java.util.stream.Collectors;
- public class RemoveDuplicatesArrayListTest extends TestCase {
- public void test() {
- final String[] values = { // from http://people.howstuffworks.com/14-pangrams.htm
- "sphinx",
- "of",
- "black",
- "quartz",
- "judge",
- "my",
- "vow",
- "two",
- "driven",
- "jocks",
- "help",
- "fax",
- "my",
- "big",
- "quiz",
- "five",
- "quacking",
- "zephyrs",
- "jolt",
- "my",
- "wax",
- "bed",
- "the",
- "five",
- "boxing",
- "wizards",
- "jump",
- "quickly",
- "pack",
- "my",
- "box",
- "with",
- "five",
- "dozen",
- "liquor",
- "jugs",
- "the",
- "quick",
- "brown",
- "fox",
- "jumps",
- "over",
- "the",
- "lazy",
- "dog",
- "jinxed",
- "wizards",
- "pluck",
- "ivy",
- "from",
- "the",
- "big",
- "quilt",
- "crazy",
- "fredrick",
- "bought",
- "many",
- "very",
- "exquisite",
- "opal",
- "jewels",
- "we",
- "promptly",
- "judged",
- "antique",
- "ivory",
- "buckles",
- "for",
- "the",
- "next",
- "prize",
- "a",
- "mad",
- "boxer",
- "shot",
- "a",
- "quick",
- "gloved",
- "jab",
- "to",
- "the",
- "jaw",
- "of",
- "his",
- "dizzy",
- "opponent",
- "jaded",
- "zombies",
- "acted",
- "quaintly",
- "but",
- "kept",
- "driving",
- "their",
- "oxen",
- "forward",
- "the",
- "job",
- "requires",
- "extra",
- "pluck",
- "and",
- "zeal",
- "from",
- "every",
- "young",
- "wage",
- "earner"
- };
- final ArrayList<String> inputArrayList = Arrays.stream(values).collect(Collectors.toCollection(ArrayList::new));
- System.out.println("inputArrayList = " + inputArrayList.toString());
- System.out.println("inputArrayList.size() = " + inputArrayList.size());
- final LinkedHashSet<String> resultSet = inputArrayList.stream().collect(Collectors.toCollection(LinkedHashSet::new));
- System.out.println("resultSet = " + resultSet.toString());
- System.out.println("resultSet.size() = " + resultSet.size());
- final ArrayList<String> outputArrayList = resultSet.stream().collect(Collectors.toCollection(ArrayList::new));
- System.out.println("outputArrayList = " + outputArrayList.toString());
- System.out.println("outputArrayList.size() = " + outputArrayList.size());
- final Iterator<String> inputIterator = inputArrayList.iterator();
- final Iterator<String> resultIterator = resultSet.iterator();
- final Iterator<String> outputIterator = outputArrayList.iterator();
- String input = inputIterator.next();
- String result = resultIterator.next();
- String output = outputIterator.next();
- while (inputIterator.hasNext()) {
- assertEquals(result, output);
- if (input.equals(output)) {
- System.out.println(input);
- result = resultIterator.next();
- output = outputIterator.next();
- } else {
- System.out.println(input + " -- dup!");
- }
- input = inputIterator.next();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement