I'm a beginner in Java and is starting to learn how to use hashsets. I have a problem with my practice exercise. The goal is to remove the duplicate description and then adding the count of similar descriptions.
For example I have,
Computer Science - 15
Engineering - 20
Dentistry - 10
Architecture - 11
Computer Science - 25
Dentistry - 7
then the output should only be:
Computer Science - 40
Engineering - 20
Dentistry - 17
Architecture - 11
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
//printing summary report
ArrayList<String> summaryReport= new ArrayList<String>();
final String[] CourseDesc = {"Computer Science", "Architecture", "Dentistry", "Computer Science"};
final int[] CourseCount = {15, 10, 10, 25};
for (String element: CourseDesc) {
for(int el: CourseCount){
summaryReport.add(element + " "+ el);
}
}
System.out.println(summaryReport);
}
}
I'm just stuck on how to add the count of similar descriptions. Thanks!