Last active
May 1, 2021 06:28
-
-
Save tremaineeto/103b1ef5546ab4c2444aafbb0f686569 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]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment