From 2748a5cc04eeb7653f3a12bb88abc4ce3e9443fe Mon Sep 17 00:00:00 2001 From: atrunz Date: Wed, 4 Mar 2026 16:29:07 -0500 Subject: [PATCH 01/11] completed hierarchy --- src/main/java/Hierachy/Hierarchy.java | 86 +++++++++++++++++++++++++++ src/main/java/Hierachy/PRACTICE.md | 34 ++++++----- 2 files changed, 106 insertions(+), 14 deletions(-) diff --git a/src/main/java/Hierachy/Hierarchy.java b/src/main/java/Hierachy/Hierarchy.java index b79931f..cc2590b 100644 --- a/src/main/java/Hierachy/Hierarchy.java +++ b/src/main/java/Hierachy/Hierarchy.java @@ -56,5 +56,91 @@ public static void main(String[] args) { for (Map.Entry entry : map.entrySet()) { System.out.println(entry.getKey() + " -> " + entry.getValue()); } + + + //challenge + + // LIST EXAMPLE + List listStudents = new ArrayList<>(); + listStudents.add("Alex"); + listStudents.add("Jonathan"); + listStudents.add("William"); + + System.out.println("List Example:"); + for (String item : listStudents) { + System.out.println(item); + } + + System.out.println(); + + // SET EXAMPLE + Set setCourses = new HashSet<>(); + setCourses.add("Math"); + setCourses.add("Reading"); + setCourses.add("Computer Science"); + + + System.out.println("Set Example:"); + for (String course : setCourses) { + System.out.println(course); + } + + System.out.println(); + + // QUEUE EXAMPLE + Queue queueTask = new LinkedList<>(); + queueTask.offer("Finish Homework"); + queueTask.offer("Wash Dishes"); + queueTask.offer("Clean Bathroom"); + + System.out.println("Queue Example:"); + while (!queueTask.isEmpty()) { + System.out.println(queueTask.poll()); + } + + System.out.println(); + + // MAP EXAMPLE + Map grade = new HashMap<>(); + grade.put("Alex", 90); + grade.put("Jonathan", 85); + grade.put("William", 95); + + System.out.println("Map Example:"); + + for (Map.Entry entry : grade.entrySet()) { + System.out.println(entry.getKey() + " -> " + entry.getValue()); + } + + + listStudents.add("Jeff"); + setCourses.add("Economics"); + queueTask.offer("Make Money"); + grade.put("Jeff", 25); + + System.out.println("List Example:"); + for (String item : listStudents) { + System.out.println(item); + } + + System.out.println("Set Example:"); + for (String course : setCourses) { + System.out.println(course); + } + + System.out.println("Queue Example:"); + while (!queueTask.isEmpty()) { + System.out.println(queueTask.poll()); + } + + System.out.println("Map Example:"); + + for (Map.Entry entry : grade.entrySet()) { + System.out.println(entry.getKey() + " -> " + entry.getValue()); + } + } } + + + diff --git a/src/main/java/Hierachy/PRACTICE.md b/src/main/java/Hierachy/PRACTICE.md index 2b885d9..905c700 100644 --- a/src/main/java/Hierachy/PRACTICE.md +++ b/src/main/java/Hierachy/PRACTICE.md @@ -12,7 +12,7 @@ These exercises help reinforce understanding of the **Java Collections Framework Which interface allows an object to be used in an enhanced for-loop? A. Collection -B. Iterable +**B. Iterable B** C. List D. Queue @@ -23,7 +23,7 @@ D. Queue Which interface is the parent of `List`, `Set`, and `Queue`? A. Iterable -B. Collection +**B. Collection** C. Map D. Deque @@ -36,7 +36,7 @@ Which of the following is **NOT part of the Collection hierarchy**? A. List B. Set C. Queue -D. Map +**D. Map** --- @@ -45,7 +45,7 @@ D. Map Which collection type allows **duplicate elements and maintains order**? A. Set -B. List +**B. List** C. Queue D. TreeSet @@ -58,7 +58,7 @@ Which structure stores **key-value pairs**? A. List B. Set C. Queue -D. Map +**D. Map** --- @@ -66,11 +66,11 @@ D. Map Write **True** or **False**. -1. `ArrayList` implements the `List` interface. -2. `Set` allows duplicate elements. -3. `Map` stores elements using keys and values. -4. `Queue` typically follows FIFO behavior. -5. `Iterable` allows collections to be used in enhanced for-loops. +1. `ArrayList` implements the `List` interface. **True** +2. `Set` allows duplicate elements. **False** +3. `Map` stores elements using keys and values. **True** +4. `Queue` typically follows FIFO behavior. **True** +5. `Iterable` allows collections to be used in enhanced for-loops. **True** --- @@ -80,12 +80,16 @@ Write **True** or **False**. What is the difference between an **interface** and a **class** in the Java Collections Framework? +Interface defines behaviors, class implement those behaviors + --- ## Question 2 Why is it recommended to declare variables using interfaces like `List` instead of concrete classes like `ArrayList`? +More flexibility and repurposability in the future + Example: ```java @@ -98,7 +102,9 @@ List list = new ArrayList<>(); Name three interfaces that extend `Collection`. ---- +List, Set, Queue + +--- # Code Reading Exercise @@ -117,9 +123,9 @@ for (String fruit : fruits) { Questions: -1. Which interface type is used for the variable? -2. Which class is used as the implementation? -3. Why can the enhanced for-loop be used here? +1. Which interface type is used for the variable? List +2. Which class is used as the implementation? ArrayList +3. Why can the enhanced for-loop be used here? Because ArrayLists are iterable --- From 775ffdb86b099db5e77673760a94d932edd4ff63 Mon Sep 17 00:00:00 2001 From: atrunz Date: Wed, 4 Mar 2026 16:35:18 -0500 Subject: [PATCH 02/11] completed iterable --- .../Iterable/Practice/IterableWarmups.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/Iterable/Practice/IterableWarmups.java b/src/main/java/Iterable/Practice/IterableWarmups.java index 9e9de94..702bfac 100644 --- a/src/main/java/Iterable/Practice/IterableWarmups.java +++ b/src/main/java/Iterable/Practice/IterableWarmups.java @@ -30,6 +30,9 @@ public static int sum(Iterable numbers) { // TODO: // Use a for-each loop to calculate the sum + for (Integer number : numbers) { + total += number; + } return total; } @@ -44,6 +47,11 @@ public static int countEven(Iterable numbers) { int count = 0; // TODO: + for (Integer number : numbers) { + if (number % 2 == 0) { + count++; + } + } // Loop through numbers // Increment count if number is even @@ -62,6 +70,11 @@ public static int findMax(Iterable numbers) { // TODO: // Loop through numbers // Update max if current number is larger + for (Integer number : numbers) { + if (number > max) { + max = number; + } + } return max; } @@ -76,6 +89,11 @@ public static int countMatches(Iterable words, String target) { int count = 0; // TODO: + for (String word : words) { + if (word.equals(target)) { + count++; + } + } // Loop through words // Compare each word to target From 255ca203a46c3f77e5b9cac874ec49e4f226a7f7 Mon Sep 17 00:00:00 2001 From: atrunz Date: Wed, 4 Mar 2026 16:41:04 -0500 Subject: [PATCH 03/11] everything in iterable except custom --- .../java/Iterable/Examples/ForEachLoopDemo.java | 12 ++++++++++-- src/main/java/Iterable/Examples/IteratorDemo.java | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/Iterable/Examples/ForEachLoopDemo.java b/src/main/java/Iterable/Examples/ForEachLoopDemo.java index a6d2198..c563d83 100644 --- a/src/main/java/Iterable/Examples/ForEachLoopDemo.java +++ b/src/main/java/Iterable/Examples/ForEachLoopDemo.java @@ -17,13 +17,17 @@ public static void main(String[] args) { // TODO: // Use a for-each loop to print each student name - + for (String student : students) { + System.out.println(student); + } System.out.println("\nPrinting students in uppercase:"); // TODO: // Use a for-each loop to print each name in uppercase - + for (String student : students) { + System.out.println(student.toUpperCase()); + } System.out.println("\nCount the number of students:"); @@ -31,6 +35,10 @@ public static void main(String[] args) { // TODO: // Use a for-each loop to count how many students are in the list + for (String student : students) { + count++; + System.out.println(student); + } System.out.println("Total students: " + count); } diff --git a/src/main/java/Iterable/Examples/IteratorDemo.java b/src/main/java/Iterable/Examples/IteratorDemo.java index b09fca7..1afde11 100644 --- a/src/main/java/Iterable/Examples/IteratorDemo.java +++ b/src/main/java/Iterable/Examples/IteratorDemo.java @@ -27,12 +27,27 @@ public static void main(String[] args) { // Use iterator.hasNext() and iterator.next() // Print each number + while (iterator.hasNext()) { + int num = iterator.next(); + System.out.println(num); + } + System.out.println("\nRemoving odd numbers using Iterator"); iterator = numbers.iterator(); // TODO: + + while (iterator.hasNext()) { + int num = iterator.next(); + if(num%2==0){ + + }else{ + iterator.remove(); + } + } + // Use iterator to remove odd numbers // Remember: use iterator.remove() From f1a4f9e0aa20f59ba962f601301c8b4da24c9507 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Mar 2026 15:40:11 -0500 Subject: [PATCH 04/11] finished collections --- .../Practice/CollectionBasics.java | 33 +++++++++++++++++++ .../Practice/CommonMethodsDemo.java | 26 ++++++++++++--- .../java/Collections/Quiz/KnowledgeCheck.md | 20 +++++------ .../java/Iterable/Examples/IteratorDemo.java | 5 +-- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/main/java/Collections/Practice/CollectionBasics.java b/src/main/java/Collections/Practice/CollectionBasics.java index e45cb49..5ab59ee 100644 --- a/src/main/java/Collections/Practice/CollectionBasics.java +++ b/src/main/java/Collections/Practice/CollectionBasics.java @@ -2,6 +2,8 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; public class CollectionBasics { public static void main(String[] args) { @@ -34,6 +36,10 @@ public static int sum(Collection numbers) { // Loop through the collection // Add each number to total + for (Integer number : numbers) { + total += number; + } + return total; } @@ -50,6 +56,12 @@ public static int countEven(Collection numbers) { // Loop through the collection // If the number is even, increase count + for (Integer number : numbers) { + if (number % 2 == 0) { + count++; + } + } + return count; } @@ -65,6 +77,11 @@ public static int findMax(Collection numbers) { // TODO: // Loop through numbers // Update max if current number is larger + for (Integer number : numbers) { + if (number > max) { + max = number; + } + } return max; } @@ -80,6 +97,11 @@ public static boolean hasDuplicates(Collection numbers) { // TODO: // Hint: // Compare the size of a collection with the size of a Set + Set set = new HashSet<>(numbers); + if (set.size() < numbers.size()) { + return true; + } + return false; } @@ -97,6 +119,12 @@ public static int countOccurrences(Collection numbers, int target) { // Loop through numbers // If number equals target, increase count + for (Integer number : numbers) { + if (number.equals(target)) { + count++; + } + } + return count; } @@ -113,6 +141,11 @@ public static Collection filterGreaterThanTwenty(Collection nu // TODO: // Loop through numbers // Add numbers greater than 20 to result + for (Integer number : numbers) { + if (number > 20) { + result.add(number); + } + } return result; } diff --git a/src/main/java/Collections/Practice/CommonMethodsDemo.java b/src/main/java/Collections/Practice/CommonMethodsDemo.java index b2dd6f9..fddf084 100644 --- a/src/main/java/Collections/Practice/CommonMethodsDemo.java +++ b/src/main/java/Collections/Practice/CommonMethodsDemo.java @@ -132,31 +132,45 @@ public static void main(String[] args) { 10, 20, 30, 40, 50 */ + Collection numbers = new ArrayList<>(); + + numbers.add(10); + numbers.add(20); + numbers.add(30); + numbers.add(40); + numbers.add(50); + /* TODO 2: Print the size of the numbers collection */ - + System.out.println(numbers.size()); /* TODO 3: Check if the collection contains 30 */ - + if(numbers.contains(30)){ + System.out.println("True"); + }else{ + System.out.println("false"); + } /* TODO 4: Remove the number 20 */ - + numbers.remove(20); /* TODO 5: Loop through the numbers collection and print each value */ - + for (Integer number : numbers) { + System.out.println(number); + } /* REFLECTION QUESTIONS: @@ -165,6 +179,10 @@ public static void main(String[] args) { 2. What methods are available because of the Collection interface? 3. What methods are NOT available when using Collection instead of List? */ + + //1. because it is a parent of list, set and queue so we can use it for all objects that are a collection + //2 .add(), .remove(), .size(), .contains(), .isEmpty(), .clear(), .addAll(), .removeAll(), .retainAll() + //3. indexing, i.e. .get() } } diff --git a/src/main/java/Collections/Quiz/KnowledgeCheck.md b/src/main/java/Collections/Quiz/KnowledgeCheck.md index 43ee11f..3cff65e 100644 --- a/src/main/java/Collections/Quiz/KnowledgeCheck.md +++ b/src/main/java/Collections/Quiz/KnowledgeCheck.md @@ -14,7 +14,7 @@ Which of the following is **true** about the `Collection` interface? A. `Collection` is a class B. `Collection` extends `List` -C. `Collection` is the root interface for most collection types +**C. `Collection` is the root interface for most collection types** D. `Collection` only stores key-value pairs --- @@ -34,7 +34,7 @@ System.out.println(numbers.size()); A. 0 B. 1 -C. 3 +**C. 3** D. 30 --- @@ -45,7 +45,7 @@ Which method is used to **check if an element exists** inside a collection? A. `search()` B. `exists()` -C. `contains()` +**C. `contains()`** D. `check()` --- @@ -66,7 +66,7 @@ System.out.println(names); ``` A. `[Alex, Jordan]` -B. `[Jordan]` +**B. `[Jordan]`** C. `[Alex]` D. `[]` @@ -77,7 +77,7 @@ D. `[]` Which method adds **all elements from another collection** into an existing collection? A. `add()` -B. `addAll()` +**B. `addAll()`** C. `insertAll()` D. `merge()` @@ -93,7 +93,7 @@ Collection numbers = new ArrayList<>(); System.out.println(numbers.isEmpty()); ``` -A. `true` +**A. `true`** B. `false` C. `0` D. Compilation error @@ -104,7 +104,7 @@ D. Compilation error Which method removes **all elements** from a collection? -A. `removeAll()` +**A. `removeAll()`** B. `deleteAll()` C. `clear()` D. `reset()` @@ -127,7 +127,7 @@ for(Integer n : nums) { } ``` -A. `5 10 15` +**A. `5 10 15`** B. `15 10 5` C. `0 1 2` D. Compilation error @@ -140,7 +140,7 @@ Which of the following **cannot be guaranteed** when using the `Collection` inte A. Elements can be added B. Elements can be removed -C. Indexed access using `.get(index)` +**C. Indexed access using `.get(index)`** D. Elements can be iterated using a loop --- @@ -155,7 +155,7 @@ Collection fruits = new ArrayList<>(); A. It automatically sorts the collection B. It prevents duplicates -C. It allows flexibility to change implementations later +**C. It allows flexibility to change implementations later** D. It forces the collection to be synchronized ``` diff --git a/src/main/java/Iterable/Examples/IteratorDemo.java b/src/main/java/Iterable/Examples/IteratorDemo.java index 1afde11..ea60b87 100644 --- a/src/main/java/Iterable/Examples/IteratorDemo.java +++ b/src/main/java/Iterable/Examples/IteratorDemo.java @@ -38,6 +38,8 @@ public static void main(String[] args) { iterator = numbers.iterator(); // TODO: + // Use iterator to remove odd numbers + // Remember: use iterator.remove() while (iterator.hasNext()) { int num = iterator.next(); @@ -48,8 +50,7 @@ public static void main(String[] args) { } } - // Use iterator to remove odd numbers - // Remember: use iterator.remove() + System.out.println("\nUpdated list:"); From f54991c94601d0e58af583d6aaabd68ef7ee0964 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Mar 2026 15:56:11 -0500 Subject: [PATCH 05/11] finished lists --- .../Lists/ArrayLists/ArrayListProblems.java | 37 +++++++++++++++++-- .../Lists/LinkedLists/LinkedListProblems.java | 10 +++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/Lists/ArrayLists/ArrayListProblems.java b/src/main/java/Lists/ArrayLists/ArrayListProblems.java index baf4dfa..d3972ad 100644 --- a/src/main/java/Lists/ArrayLists/ArrayListProblems.java +++ b/src/main/java/Lists/ArrayLists/ArrayListProblems.java @@ -2,6 +2,8 @@ import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; public class ArrayListProblems { @@ -34,6 +36,10 @@ public static void main(String[] args) { public static int sum(List nums) { // TODO: Implement this method + int sum = 0; + for (int num : nums){ + sum += num; + } return 0; } @@ -50,6 +56,14 @@ public static int countEvens(List nums) { // TODO: Implement this method + int evenCount = 0; + + for (int num : nums){ + if (num % 2 == 0){ + evenCount++; + } + } + return 0; } @@ -68,7 +82,13 @@ public static boolean hasDuplicate(List nums) { // TODO: Implement this method - return false; + Collection collection2 = new HashSet (nums); + + if (collection2.size() == nums.size()){ + return false; + } + + return true; } /* @@ -82,8 +102,15 @@ public static boolean hasDuplicate(List nums) { public static int findMax(List nums) { // TODO: Implement this method + int max = Integer.MIN_VALUE; - return 0; + for (int num : nums){ + if (num > max){ + max = num; + } + } + + return max; } /* @@ -99,7 +126,11 @@ public static int findMax(List nums) { public static List reverse(List nums) { // TODO: Implement this method + List list = new ArrayList<>(); + for (int i = nums.size() - 1; i >= 0; i--){ + list.add(nums.get(i)); + } - return null; + return list; } } diff --git a/src/main/java/Lists/LinkedLists/LinkedListProblems.java b/src/main/java/Lists/LinkedLists/LinkedListProblems.java index 178a2ba..ed230aa 100644 --- a/src/main/java/Lists/LinkedLists/LinkedListProblems.java +++ b/src/main/java/Lists/LinkedLists/LinkedListProblems.java @@ -38,6 +38,7 @@ public static void main(String[] args) { public static void addToFront(LinkedList list, int value) { // TODO: Implement this method + list.addFirst(value); } @@ -52,6 +53,7 @@ public static void addToFront(LinkedList list, int value) { public static void addToEnd(LinkedList list, int value) { // TODO: Implement this method + list.addLast(value); } @@ -66,6 +68,7 @@ public static void addToEnd(LinkedList list, int value) { public static void removeFirstElement(LinkedList list) { // TODO: Implement this method + list.removeFirst(); } @@ -80,7 +83,7 @@ public static void removeFirstElement(LinkedList list) { public static void removeLastElement(LinkedList list) { // TODO: Implement this method - + list.removeLast(); } /* @@ -95,7 +98,8 @@ public static int getFirstElement(LinkedList list) { // TODO: Implement this method - return 0; + return list.getFirst(); + } /* @@ -110,6 +114,6 @@ public static int getLastElement(LinkedList list) { // TODO: Implement this method - return 0; + return list.getLast(); } } From 93aea2bf20a2be1a422f9215db3d1268a83c9815 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Mar 2026 16:08:33 -0500 Subject: [PATCH 06/11] finished sets --- src/main/java/Sets/HashSet/HashSetProblems.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/Sets/HashSet/HashSetProblems.java b/src/main/java/Sets/HashSet/HashSetProblems.java index a36c570..faf7ae1 100644 --- a/src/main/java/Sets/HashSet/HashSetProblems.java +++ b/src/main/java/Sets/HashSet/HashSetProblems.java @@ -1,5 +1,7 @@ package Sets.HashSet; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -21,6 +23,7 @@ public static void main(String[] args) { public static void addElement(Set set, String value) { // TODO: Implement this method + set.add(value); } @@ -35,7 +38,9 @@ public static void addElement(Set set, String value) { public static boolean containsValue(Set set, String value) { // TODO: Implement this method - + if (set.contains(value)){ + return true; + } return false; } @@ -50,6 +55,7 @@ public static boolean containsValue(Set set, String value) { public static void removeValue(Set set, String value) { // TODO: Implement this method + set.remove(value); } @@ -63,9 +69,10 @@ public static void removeValue(Set set, String value) { */ public static int getUniqueCount(Set set) { + // TODO: Implement this method + return set.size(); - return 0; } /* @@ -79,7 +86,7 @@ public static int getUniqueCount(Set set) { public static Set getUniqueValues(List numbers) { // TODO: Implement this method - - return null; + Set uniqueValues = new HashSet<>(numbers); + return uniqueValues; } } From 3a38ba90d64ba14482f379333aafb061afa0e41a Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Mar 2026 16:18:27 -0500 Subject: [PATCH 07/11] finished queues --- src/main/java/Queues/Deque/DequeProblems.java | 10 ++++++---- src/main/java/Sets/HashSet/HashSetProblems.java | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/Queues/Deque/DequeProblems.java b/src/main/java/Queues/Deque/DequeProblems.java index 7ef0c06..a05cbe6 100644 --- a/src/main/java/Queues/Deque/DequeProblems.java +++ b/src/main/java/Queues/Deque/DequeProblems.java @@ -20,6 +20,7 @@ public static void main(String[] args) { public static void addFront(Deque deque, int value) { // TODO: Implement this method + deque.addFirst(value); } @@ -34,6 +35,7 @@ public static void addFront(Deque deque, int value) { public static void addBack(Deque deque, int value) { // TODO: Implement this method + deque.addLast(value); } @@ -48,8 +50,8 @@ public static void addBack(Deque deque, int value) { public static Integer removeFront(Deque deque) { // TODO: Implement this method + return deque.pollFirst(); - return null; } /* @@ -64,7 +66,7 @@ public static Integer removeBack(Deque deque) { // TODO: Implement this method - return null; + return deque.pollLast(); } /* @@ -79,7 +81,7 @@ public static Integer peekFront(Deque deque) { // TODO: Implement this method - return null; + return deque.peekFirst(); } /* @@ -94,7 +96,7 @@ public static Integer peekBack(Deque deque) { // TODO: Implement this method - return null; + return deque.peekLast(); } } diff --git a/src/main/java/Sets/HashSet/HashSetProblems.java b/src/main/java/Sets/HashSet/HashSetProblems.java index faf7ae1..6a889d1 100644 --- a/src/main/java/Sets/HashSet/HashSetProblems.java +++ b/src/main/java/Sets/HashSet/HashSetProblems.java @@ -10,6 +10,7 @@ public static void main(String[] args) { // You can test your methods here + } /* From 67f0d0616412b60eaa007ba599bc2a5c581e6b97 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Mar 2026 16:56:03 -0500 Subject: [PATCH 08/11] maps complete --- src/main/java/Maps/HashMap/HashMapProblems.java | 17 ++++++++++++++--- .../LinkedHashMap/LinkedHashMapProblems.java | 17 +++++++++++++++-- src/main/java/Maps/TreeMap/TreeMapProblems.java | 9 ++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/Maps/HashMap/HashMapProblems.java b/src/main/java/Maps/HashMap/HashMapProblems.java index 04b5567..7fd3f75 100644 --- a/src/main/java/Maps/HashMap/HashMapProblems.java +++ b/src/main/java/Maps/HashMap/HashMapProblems.java @@ -35,6 +35,7 @@ public static void main(String[] args) { public static void addItem(Map map, String item, int quantity) { // TODO: Implement this method + map.put(item, quantity); } @@ -50,7 +51,7 @@ public static int getQuantity(Map map, String item) { // TODO: Implement this method - return 0; + return map.get(item); } /* @@ -64,6 +65,7 @@ public static int getQuantity(Map map, String item) { public static void updateQuantity(Map map, String item, int newQuantity) { // TODO: Implement this method + map.put(item, newQuantity); } @@ -78,6 +80,7 @@ public static void updateQuantity(Map map, String item, int new public static void removeItem(Map map, String item) { // TODO: Implement this method + map.remove(item); } @@ -91,8 +94,16 @@ public static void removeItem(Map map, String item) { */ public static Map countFrequency(List numbers) { + HashMap map = new HashMap<>(); // TODO: Implement this method - - return null; + for (int number : numbers) { + if(map.containsKey(number)) { + map.put(number, map.get(number) + 1); + }else{ + map.put(number, 1); + } + } + + return map; } } diff --git a/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java b/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java index e8bbdc2..6a03c7d 100644 --- a/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java +++ b/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java @@ -33,6 +33,7 @@ public static void main(String[] args) { public static void addStudent(Map map, String name, int grade) { // TODO: Implement this method + map.put(name, grade); } @@ -47,6 +48,7 @@ public static void addStudent(Map map, String name, int grade) public static void updateGrade(Map map, String name, int newGrade) { // TODO: Implement this method + map.put(name, newGrade); } @@ -61,6 +63,7 @@ public static void updateGrade(Map map, String name, int newGra public static void removeStudent(Map map, String name) { // TODO: Implement this method + map.remove(name); } @@ -76,7 +79,7 @@ public static String getFirstInserted(Map map) { // TODO: Implement this method - return null; + return map.keySet().iterator().next(); } /* @@ -92,6 +95,16 @@ public static Map wordFrequency(List words) { // TODO: Implement this method - return null; + LinkedHashMap map = new LinkedHashMap<>(); + + for (String word : words) { + if(map.containsKey(word)) { + map.put(word, map.get(word) + 1); + }else{ + map.put(word, 1); + } + } + + return map; } } diff --git a/src/main/java/Maps/TreeMap/TreeMapProblems.java b/src/main/java/Maps/TreeMap/TreeMapProblems.java index b101d2e..929dfda 100644 --- a/src/main/java/Maps/TreeMap/TreeMapProblems.java +++ b/src/main/java/Maps/TreeMap/TreeMapProblems.java @@ -31,6 +31,7 @@ public static void main(String[] args) { public static void addPlayer(TreeMap map, int rank, String name) { // TODO: Implement this method + map.put(rank, name); } @@ -46,7 +47,7 @@ public static String getTopPlayer(TreeMap map) { // TODO: Implement this method - return null; + return map.get(map.firstKey()); } /* @@ -61,7 +62,8 @@ public static String getLowestPlayer(TreeMap map) { // TODO: Implement this method - return null; + return map.get(map.lastKey()); + } /* @@ -75,6 +77,7 @@ public static String getLowestPlayer(TreeMap map) { public static void removePlayer(TreeMap map, int rank) { // TODO: Implement this method + map.remove(rank); } @@ -90,6 +93,6 @@ public static Integer getNextRank(TreeMap map, int rank) { // TODO: Implement this method - return null; + return map.higherKey(rank); } } From fdaba5ed40d643d36588ae5dfca4eb25df2e67ba Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Mar 2026 03:48:51 -0500 Subject: [PATCH 09/11] partially completed hackerrank --- .../CollectionsHackerrankProblems.java | 71 +++++++++++++++++-- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java b/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java index 6c2f4e1..2255d5a 100644 --- a/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java +++ b/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java @@ -1,8 +1,6 @@ package CollectionsHackerrank; -import java.util.List; -import java.util.Map; -import java.util.Queue; +import java.util.*; public class CollectionsHackerrankProblems { public class CollectionsHackerrankPractice { @@ -10,6 +8,9 @@ public class CollectionsHackerrankPractice { public static void main(String[] args) { // You can test your methods here + removeDuplicates(Arrays.asList(1,2,2,3,4,4,5)); + countFrequency(Arrays.asList(1,2,2,3,4,4,5)); + } @@ -24,8 +25,10 @@ public static void main(String[] args) { public static List removeDuplicates(List numbers) { // TODO: Implement this method + Set set = new HashSet<>(numbers); + List result = new ArrayList<>(set); - return null; + return result; } /* @@ -39,8 +42,17 @@ public static List removeDuplicates(List numbers) { public static Map countFrequency(List numbers) { // TODO: Implement this method + Map map = new HashMap<>(); - return null; + for (Integer number : numbers) { + if (map.containsKey(number)) { + map.put(number, map.get(number) + 1); + }else{ + map.put(number, 1); + } + } + + return map; } /* @@ -54,6 +66,17 @@ public static Map countFrequency(List numbers) { public static Integer firstUnique(List numbers) { // TODO: Implement this method + Map map = new HashMap<>(); + + for (Integer number : numbers) { + if (map.containsKey(number)) { + map.put(number, map.get(number) + 1); + }else{ + map.put(number, 1); + } + } + + map. return null; } @@ -71,6 +94,13 @@ public static Integer firstUnique(List numbers) { public static boolean twoSum(List numbers, int target) { // TODO: Implement this method + for (int i = 0; i < numbers.size(); i++) { + for (int j = i+1; j < numbers.size()-1; j++) { + if(numbers.get(i) + numbers.get(j) == target){ + return true; + } + } + } return false; } @@ -86,8 +116,11 @@ public static boolean twoSum(List numbers, int target) { public static int countUniqueWords(List words) { // TODO: Implement this method + Set wordSet = new HashSet<>(words); + + return wordSet.size(); + - return 0; } /* @@ -102,7 +135,12 @@ public static Queue reverseQueue(Queue queue) { // TODO: Implement this method - return null; + Queue result = new ArrayDeque<>(); + + for(int i = 0; i < queue.size(); i++){ + result.add(queue.poll()); + } + return result; } /* @@ -120,6 +158,21 @@ public static boolean isBalanced(String expression) { // TODO: Implement this method + Map map = new HashMap<>(); + + for(int i = 0; i < expression.length(); i++){ + if(map.containsKey(expression.charAt(i))){ + map.put(expression.charAt(i), map.get(expression.charAt(i)) + 1); + }else{ + map.put(expression.charAt(i), 1); + } + } + + if (map.get('(') == map.get(')')) { + return true; + } + + return false; } @@ -172,6 +225,10 @@ public static int maxSlidingWindowSum(List numbers, int k) { // TODO: Implement this method + for (int i = 0; i < numbers.size(); i = i + k) { + + } + return 0; } } From 724add97dc0c5584d9601673c79fefd16fc024ea Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Mar 2026 11:04:39 -0500 Subject: [PATCH 10/11] initial completion --- .../CollectionsHackerrankProblems.java | 66 ++++++++++++++++--- src/main/java/Queues/Deque/DequeProblems.java | 8 +++ .../java/Sets/HashSet/HashSetProblems.java | 22 +++++-- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java b/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java index 2255d5a..532f7f0 100644 --- a/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java +++ b/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java @@ -11,7 +11,6 @@ public static void main(String[] args) { removeDuplicates(Arrays.asList(1,2,2,3,4,4,5)); countFrequency(Arrays.asList(1,2,2,3,4,4,5)); - } /* @@ -76,7 +75,13 @@ public static Integer firstUnique(List numbers) { } } - map. + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 1) { + return entry.getKey(); + } + } + + return null; } @@ -187,8 +192,30 @@ public static boolean isBalanced(String expression) { public static Integer mostFrequent(List numbers) { // TODO: Implement this method + int max = numbers.getFirst(); + int maxKey = numbers.getFirst(); + Map map = new HashMap<>(); + + for (Integer number : numbers) { + if (map.containsKey(number)) { + map.put(number, map.get(number) + 1); + }else{ + map.put(number, 1); + } + } + + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() > max) { + max = entry.getValue(); + maxKey = entry.getKey(); + } + + + } + return maxKey; + + - return null; } /* @@ -206,9 +233,19 @@ public static Integer mostFrequent(List numbers) { */ public static Map> groupByLength(List words) { - // TODO: Implement this method + Map> result = new HashMap<>(); - return null; + for (String word : words) { + int length = word.length(); + + if (!result.containsKey(length)) { + result.put(length, new ArrayList<>()); + } + + result.get(length).add(word); + } + + return result; } /* @@ -225,11 +262,24 @@ public static int maxSlidingWindowSum(List numbers, int k) { // TODO: Implement this method - for (int i = 0; i < numbers.size(); i = i + k) { + if (numbers.size() < k){ + return numbers.getFirst(); + } + int max = Integer.MIN_VALUE; + for (int i = 0; i < numbers.size()-k+1; i++) { + int maxTest = 0; + for(int j = i; j < i+k; j++){ + maxTest = numbers.get(j) + maxTest; + } + if (maxTest > max) { + max = maxTest; + } + + + } + return max; } - return 0; } } -} diff --git a/src/main/java/Queues/Deque/DequeProblems.java b/src/main/java/Queues/Deque/DequeProblems.java index a05cbe6..475380c 100644 --- a/src/main/java/Queues/Deque/DequeProblems.java +++ b/src/main/java/Queues/Deque/DequeProblems.java @@ -1,11 +1,19 @@ package Queues.Deque; +import java.util.ArrayDeque; import java.util.Deque; public class DequeProblems { public static void main(String[] args) { // You can test your methods here + Deque deque = new ArrayDeque<>(); + addFront(deque, 5); + addBack(deque, 10); + removeFront(deque); + removeBack(deque); + peekFront(deque); + } diff --git a/src/main/java/Sets/HashSet/HashSetProblems.java b/src/main/java/Sets/HashSet/HashSetProblems.java index 6a889d1..c4e6bc9 100644 --- a/src/main/java/Sets/HashSet/HashSetProblems.java +++ b/src/main/java/Sets/HashSet/HashSetProblems.java @@ -1,14 +1,28 @@ package Sets.HashSet; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class HashSetProblems { public static void main(String[] args) { // You can test your methods here + Set set = new HashSet<>(); + List nums = new ArrayList<>(); + nums.add(1); + nums.add(2); + nums.add(2); + nums.add(3); + nums.add(3); + nums.add(3); + + addElement(set, "apple"); + + containsValue(set, "apple"); + containsValue(set, "banana"); + removeValue(set, "apple"); + getUniqueCount(set); + getUniqueValues(nums); + } From 2adfd81436b36120c6f9254f5bd22f5954af2848 Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Mar 2026 11:53:36 -0500 Subject: [PATCH 11/11] fixed implementations and tests --- .../CollectionsHackerrankProblems.java | 82 +++++++++---------- src/main/java/CollectionsHackerrank/Main.java | 30 +++++++ .../java/Maps/HashMap/HashMapProblems.java | 3 + .../LinkedHashMap/LinkedHashMapProblems.java | 6 ++ .../java/Maps/TreeMap/TreeMapProblems.java | 2 + .../Queues/ArrayDeque/ArrayDequeProblems.java | 15 ++-- src/main/java/Queues/Deque/DequeProblems.java | 13 ++- .../java/Sets/HashSet/HashSetProblems.java | 10 ++- 8 files changed, 107 insertions(+), 54 deletions(-) create mode 100644 src/main/java/CollectionsHackerrank/Main.java diff --git a/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java b/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java index 532f7f0..7f0d0c8 100644 --- a/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java +++ b/src/main/java/CollectionsHackerrank/CollectionsHackerrankProblems.java @@ -8,8 +8,8 @@ public class CollectionsHackerrankPractice { public static void main(String[] args) { // You can test your methods here - removeDuplicates(Arrays.asList(1,2,2,3,4,4,5)); - countFrequency(Arrays.asList(1,2,2,3,4,4,5)); + System.out.println(removeDuplicates(Arrays.asList(1,2,2,3,4,4,5))); + System.out.println(countFrequency(Arrays.asList(1,2,2,3,4,4,5))); } @@ -24,10 +24,8 @@ public static void main(String[] args) { public static List removeDuplicates(List numbers) { // TODO: Implement this method - Set set = new HashSet<>(numbers); - List result = new ArrayList<>(set); + return new ArrayList<>(new LinkedHashSet<>(numbers)); - return result; } /* @@ -64,25 +62,18 @@ public static Map countFrequency(List numbers) { */ public static Integer firstUnique(List numbers) { - // TODO: Implement this method Map map = new HashMap<>(); for (Integer number : numbers) { - if (map.containsKey(number)) { - map.put(number, map.get(number) + 1); - }else{ - map.put(number, 1); - } + map.put(number, map.getOrDefault(number, 0) + 1); } - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 1) { - return entry.getKey(); + for (Integer number : numbers) { + if (map.get(number) == 1) { + return number; } } - - return null; } @@ -100,7 +91,7 @@ public static boolean twoSum(List numbers, int target) { // TODO: Implement this method for (int i = 0; i < numbers.size(); i++) { - for (int j = i+1; j < numbers.size()-1; j++) { + for (int j = i+1; j < numbers.size(); j++) { if(numbers.get(i) + numbers.get(j) == target){ return true; } @@ -140,11 +131,17 @@ public static Queue reverseQueue(Queue queue) { // TODO: Implement this method - Queue result = new ArrayDeque<>(); + Stack stack = new Stack<>(); - for(int i = 0; i < queue.size(); i++){ - result.add(queue.poll()); + while (!queue.isEmpty()) { + stack.push(queue.poll()); } + + Queue result = new ArrayDeque<>(); + while (!stack.isEmpty()) { + result.add(stack.pop()); + } + return result; } @@ -163,22 +160,23 @@ public static boolean isBalanced(String expression) { // TODO: Implement this method - Map map = new HashMap<>(); + int balance = 0; - for(int i = 0; i < expression.length(); i++){ - if(map.containsKey(expression.charAt(i))){ - map.put(expression.charAt(i), map.get(expression.charAt(i)) + 1); - }else{ - map.put(expression.charAt(i), 1); + for (int i = 0; i < expression.length(); i++) { + char c = expression.charAt(i); + + if (c == '(') { + balance++; + } else if (c == ')') { + balance--; } - } - if (map.get('(') == map.get(')')) { - return true; + if (balance < 0) { + return false; + } } - - return false; + return balance == 0; } /* @@ -192,26 +190,22 @@ public static boolean isBalanced(String expression) { public static Integer mostFrequent(List numbers) { // TODO: Implement this method - int max = numbers.getFirst(); - int maxKey = numbers.getFirst(); Map map = new HashMap<>(); for (Integer number : numbers) { - if (map.containsKey(number)) { - map.put(number, map.get(number) + 1); - }else{ - map.put(number, 1); - } + map.put(number, map.getOrDefault(number, 0) + 1); } + int maxFreq = 0; + Integer maxKey = null; + for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() > max) { - max = entry.getValue(); + if (entry.getValue() > maxFreq) { + maxFreq = entry.getValue(); maxKey = entry.getKey(); } - - } + return maxKey; @@ -262,8 +256,8 @@ public static int maxSlidingWindowSum(List numbers, int k) { // TODO: Implement this method - if (numbers.size() < k){ - return numbers.getFirst(); + if (numbers == null || numbers.isEmpty() || k <= 0 || k > numbers.size()) { + throw new IllegalArgumentException("Invalid input"); } int max = Integer.MIN_VALUE; for (int i = 0; i < numbers.size()-k+1; i++) { diff --git a/src/main/java/CollectionsHackerrank/Main.java b/src/main/java/CollectionsHackerrank/Main.java new file mode 100644 index 0000000..a3cbda1 --- /dev/null +++ b/src/main/java/CollectionsHackerrank/Main.java @@ -0,0 +1,30 @@ +package CollectionsHackerrank; + +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Queue; + +public class Main { + public static void main(String[] args) { + + Queue queue = new ArrayDeque<>(); + queue.offer(1); + queue.offer(2); + queue.offer(3); + queue.offer(4); + + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.removeDuplicates(Arrays.asList(1, 2, 2, 3, 4, 4, 5))); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.countFrequency(Arrays.asList(1, 2, 2, 3, 4, 4, 5))); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.firstUnique(Arrays.asList(1, 2, 2, 3, 4, 4, 5))); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.twoSum(Arrays.asList(1, 2, 2, 3, 4, 4, 5), 7)); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.countUniqueWords(Arrays.asList("Apple", "Orange", "Orange", "Pear"))); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.reverseQueue(queue)); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.isBalanced("()")); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.isBalanced("((()")); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.mostFrequent(Arrays.asList(1, 2, 2, 3, 4, 4, 5))); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.groupByLength(Arrays.asList("Apple", "Orange", "Orange", "Pear"))); + System.out.println(CollectionsHackerrankProblems.CollectionsHackerrankPractice.maxSlidingWindowSum(Arrays.asList(1, 2, 2, 3, 4, 4, 5), 2)); + + + } +} diff --git a/src/main/java/Maps/HashMap/HashMapProblems.java b/src/main/java/Maps/HashMap/HashMapProblems.java index 7fd3f75..99ad170 100644 --- a/src/main/java/Maps/HashMap/HashMapProblems.java +++ b/src/main/java/Maps/HashMap/HashMapProblems.java @@ -1,5 +1,6 @@ package Maps.HashMap; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,6 +23,8 @@ public static void main(String[] args) { removeItem(inventory, "Oranges"); System.out.println("After Removal: " + inventory); + System.out.println("Frequency: " + countFrequency(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 9))); + } /* diff --git a/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java b/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java index 6a03c7d..ea6afd4 100644 --- a/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java +++ b/src/main/java/Maps/LinkedHashMap/LinkedHashMapProblems.java @@ -1,5 +1,6 @@ package Maps.LinkedHashMap; +import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -20,6 +21,11 @@ public static void main(String[] args) { removeStudent(studentGrades, "Morgan"); System.out.println("After Removal: " + studentGrades); + + System.out.println("First inserted: " + getFirstInserted(studentGrades)); + + System.out.println("Word frequency: " + wordFrequency(Arrays.asList("Taylor", "Morgan", "Taylor", "Taylor", "Jeef", "bob"))); + } /* diff --git a/src/main/java/Maps/TreeMap/TreeMapProblems.java b/src/main/java/Maps/TreeMap/TreeMapProblems.java index 929dfda..50fd2ea 100644 --- a/src/main/java/Maps/TreeMap/TreeMapProblems.java +++ b/src/main/java/Maps/TreeMap/TreeMapProblems.java @@ -18,6 +18,8 @@ public static void main(String[] args) { removePlayer(rankings, 2); System.out.println("After removal: " + rankings); + + System.out.println("Get next rank" + getNextRank(rankings, 1)); } /* diff --git a/src/main/java/Queues/ArrayDeque/ArrayDequeProblems.java b/src/main/java/Queues/ArrayDeque/ArrayDequeProblems.java index dac03cf..9f26a4f 100644 --- a/src/main/java/Queues/ArrayDeque/ArrayDequeProblems.java +++ b/src/main/java/Queues/ArrayDeque/ArrayDequeProblems.java @@ -18,6 +18,10 @@ public static void main(String[] args) { removeBack(numbers); System.out.println("After removing back: " + numbers); + + System.out.println("Deque front: " + peekFront(numbers)); + System.out.println("Deque back: " + peekBack(numbers)); + } /* @@ -31,6 +35,7 @@ public static void main(String[] args) { public static void addToFront(ArrayDeque deque, int value) { // TODO: Implement this method + deque.addFirst(value); } @@ -45,7 +50,7 @@ public static void addToFront(ArrayDeque deque, int value) { public static void addToBack(ArrayDeque deque, int value) { // TODO: Implement this method - + deque.addLast(value); } /* @@ -59,7 +64,7 @@ public static void addToBack(ArrayDeque deque, int value) { public static void removeFront(ArrayDeque deque) { // TODO: Implement this method - + deque.removeFirst(); } /* @@ -73,7 +78,7 @@ public static void removeFront(ArrayDeque deque) { public static void removeBack(ArrayDeque deque) { // TODO: Implement this method - + deque.removeLast(); } /* @@ -88,7 +93,7 @@ public static Integer peekFront(ArrayDeque deque) { // TODO: Implement this method - return null; + return deque.peekFirst(); } /* @@ -103,6 +108,6 @@ public static Integer peekBack(ArrayDeque deque) { // TODO: Implement this method - return null; + return deque.peekLast(); } } diff --git a/src/main/java/Queues/Deque/DequeProblems.java b/src/main/java/Queues/Deque/DequeProblems.java index 475380c..f77eb22 100644 --- a/src/main/java/Queues/Deque/DequeProblems.java +++ b/src/main/java/Queues/Deque/DequeProblems.java @@ -9,10 +9,21 @@ public static void main(String[] args) { // You can test your methods here Deque deque = new ArrayDeque<>(); addFront(deque, 5); + System.out.println(deque); addBack(deque, 10); + System.out.println(deque); removeFront(deque); + System.out.println(deque); removeBack(deque); - peekFront(deque); + System.out.println(deque); + addFront(deque, 5); + addFront(deque, 19); + addFront(deque, 52); + + System.out.println(peekFront(deque)); + System.out.println(peekBack(deque)); + + } diff --git a/src/main/java/Sets/HashSet/HashSetProblems.java b/src/main/java/Sets/HashSet/HashSetProblems.java index c4e6bc9..f98a238 100644 --- a/src/main/java/Sets/HashSet/HashSetProblems.java +++ b/src/main/java/Sets/HashSet/HashSetProblems.java @@ -17,11 +17,13 @@ public static void main(String[] args) { addElement(set, "apple"); - containsValue(set, "apple"); - containsValue(set, "banana"); + System.out.println(set); + System.out.println(containsValue(set, "apple")); + System.out.println(containsValue(set, "banana")); removeValue(set, "apple"); - getUniqueCount(set); - getUniqueValues(nums); + System.out.println(set); + System.out.println(getUniqueCount(set)); + System.out.println(getUniqueValues(nums));