Created
May 1, 2021 06:22
-
-
Save tremaineeto/89bcfc55714ea3bc5ddb1142889bc43e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String[][] peopleToGrades = { | |
{"Tremaine", "A"}, | |
{"Jeremy", "A-"}, | |
{"Yuta", "B"}, | |
{"Steph", "A+"}, | |
{"Klay", "B+"}, | |
{"Damian", "A"}, | |
{"Klay", "A"}, | |
{"Jeremy", "B-"}, | |
}; | |
HashMap<String, ArrayList<String>> peopleToGradesMap = new HashMap<>(); | |
for (int i = 0; i < peopleToGrades.length; i++) { | |
if (!peopleToGradesMap.containsKey(peopleToGrades[i][0])) { // [i][0] is the name of the person | |
peopleToGradesMap.put(peopleToGrades[i][0], new ArrayList<String>()); // ArrayList is empty at this point | |
peopleToGradesMap.get(peopleToGrades[i][0]).add(peopleToGrades[i][1]); | |
} else { | |
peopleToGradesMap.get(peopleToGrades[i][0]).add(peopleToGrades[i][1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment