I know, this is an old question. But just for the sake of completeness, the lambda version.

Map<String, List<Item>> items = new HashMap<>();
items.computeIfAbsent(key, k -> new ArrayList<>()).add(item);
Answer from pan on Stack Overflow
🌐
Reddit
reddit.com › r/learnjava › how to populate an arraylist in a hashmap?
r/learnjava on Reddit: How to populate an ArrayList in a HashMap?
May 31, 2021 -

I found a thread on stackoverflow, but I'm just not tracking how to do this in my program.

I am reading the book "Job Ready Java" and one of the exercises is to create a program of student quiz scores that stores their name as a String and scores as an ArrayList in a Hashmap. I think what they want is for there to be a Hashmap like this:

StudentNam(key) : Scores(values)

Bob : [47, 59, 60, 27]

Frank : [89, 79, 80, 90]

I completely cannot fathom how to add multiple values into Scores using a HashMap. If it was just a HashMap<String, Integer> then I would do:

Hashmap<String, Integer> students = new HashMap<String, Integer>();
students.put("Bob" 69);

But how to enter an array of values to represent Bob's scores if he has like 10 scores? TYIA and sorry if this is kind of stream of conscious question, but I'm racking my brain on this one.

Discussions

java - How to add HashMap to ArrayList - Stack Overflow
Can someone please tell me why the code below overwrites every element in the ArrayList with the most recent entry into the ArrayList? Or how to correctly add new elements of hashmaps to my ArrayL... More on stackoverflow.com
🌐 stackoverflow.com
java - Best way to create a hashmap of arraylist - Stack Overflow
I have one million rows of data in .txt format. the format is very simple. For each row: user1,value1 user2,value2 user3,value3 user1,value4 ... You know what I mean. For each user, it could appea... More on stackoverflow.com
🌐 stackoverflow.com
data structures - how to use hashmap and arraylist in Java - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
How to add arraylist in hashmap in java using object of class - Stack Overflow
I want to write a program ask the user to enter numerator and denominator and store them in a matrix and arrange it by hashmap the following is the question I wrote the code but I still have wrongs: More on stackoverflow.com
🌐 stackoverflow.com
April 26, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-arraylist-to-hashmap-in-java
Convert ArrayList to HashMap in Java - GeeksforGeeks
July 23, 2025 - Array List can be converted into HashMap, but the HashMap does not maintain the order of ArrayList.
🌐
Java67
java67.com › 2017 › 10 › java-8-convert-arraylist-to-hashmap-or.html
How to convert ArrayList to HashMap and LinkedHashMap in Java 8 - Example Tutorial | Java67
The toMap() method, which we'll use to convert an ArrayList to HashMap, is overloaded, and it allows you to specify which elements to keep and which element to discard in case of duplicates.
🌐
Quora
quora.com › How-do-I-add-an-ArrayList-to-a-Java-HashMap
How to add an ArrayList to a Java HashMap - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Coderanch
coderanch.com › t › 631749 › java › arraylist-index-items-hashmap-key
Using arraylist index and items as hashmap key and values? (Beginning Java forum at Coderanch)
April 6, 2014 - Third: Your ArrayList should be defined as: ArrayList<String> array = new ArrayList<String>(); Fourth: Since (I assume) you want each entry in your ArrayList to correspond with a single mapping in your Map, try: Map<Integer, String> actors = new HashMap<Integer, String>(); instead.
🌐
TutorialsPoint
tutorialspoint.com › convert-arraylist-to-hashmap-in-java
Convert ArrayList to HashMap in Java
June 17, 2024 - Approach 2 Java program for list convert in HashMap with the help of Java 8 Stream and ASCII characters table methods · Use of ConvertArrayListToHashMap(), List, Collectors.toMap(), Collectors.groupingBy() and Iteration Method Directly Which ...
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java collections › java map › add values to arraylist used as value in hashmap in java
Add Values to ArrayList Used as Value in HashMap in Java | Baeldung
July 27, 2026 - Map<String, List<String>> map = new HashMap<>(); ArrayListInHashMap.addKeyManually(map, K1, K1_V1); ArrayListInHashMap.addKeyManually(map, K1, K1_V2); ArrayListInHashMap.addKeyManually(map, K2, K2_V1); This will construct a map that looks like ...
🌐
Quora
quora.com › How-do-you-add-an-element-to-an-arraylist-thats-in-a-hashmap
How to add an element to an arraylist that's in a hashmap - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Bukkit
bukkit.org › threads › arraylists-inside-of-a-hashmap.378937
ArrayLists inside of a HashMap. | Bukkit Forums
I've been trying to add a team's feature into my plugin and yes I know there's hundreds of plugins out there that do this but I want to learn it. I did...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-hashmap-to-arraylist-in-java
How to Convert HashMap to ArrayList in Java? - GeeksforGeeks
July 15, 2025 - If we need an ArrayList containing only the keys from the HashMap, we can use the keySet() method in the HashMap and convert it to an ArrayList.
🌐
Code2test
code2test.com › home › how to put arraylist in hashmap in java
how to put arraylist in hashmap in java Archives - code2test: Testing site
Home » Posts tagged 'how to put arraylist in hashmap in java' Introduction of related Topics · 6th March 2020 · In this tutorial learn how to put multiple values in single Key in HashMap. Code: Consider above code for adding multiple values in single key in hashmap Further topics on selenium, navigate to link ·
🌐
Baeldung
baeldung.com › home › java › java collections › java map › how to store hashmap inside a list
How to Store HashMap Inside a List | Baeldung
April 3, 2025 - HashMap<String, List<String>> ... booksAuthorsMapsList to hold HashMaps for different categories: List<HashMap<String, List<String>>> booksAuthorsMapsList = new ArrayList<>(); Now, we have a List containing two HashMaps....
Top answer
1 of 1
2

I think what you need is a Map of Map of List.ie.,

Map< String, Map< String, List< String>>>

Sample code below:

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Test {
public static void main(String[] args) throws IOException {

    Map<String,Map<String,List<String>>> scheduleMap=new HashMap<>();

    //Adding
    addSchedule(scheduleMap, "1111", "Engineering", "Tue3");
    addSchedule(scheduleMap, "1111", "Engineering", "Wed2");
    addSchedule(scheduleMap, "1111", "Math", "Wed4");
    addSchedule(scheduleMap, "1111", "Physics", "Fri10");
    addSchedule(scheduleMap, "2222", "Engineering", "Wed2");
    addSchedule(scheduleMap, "2222", "Chemistry ", "Wed4");

    //Printing
    printSchedule(scheduleMap);

}

private static void printSchedule(Map<String, Map<String, List<String>>> scheduleMap) {
    //Sample printing
    for(Entry<String, Map<String, List<String>>> staff : scheduleMap.entrySet()) {
        for(Entry<String,List<String>> subject:staff.getValue().entrySet()) {
            StringBuilder sb=new StringBuilder();
            sb.append(staff.getKey()).append(" : ").append(subject.getKey()).append(" : ");
            for(String sessionTime: subject.getValue()) {
                sb.append(sessionTime).append(", ");
            }
            sb.setLength(sb.length()-2);
            System.out.println(sb.toString());
        }
    }
}

public static void addSchedule(Map<String,Map<String,List<String>>> scheduleMap, String id,String subject,String sessionTime) {
    if(!scheduleMap.containsKey(id)) {
        scheduleMap.put(id, new HashMap<String,List<String>>());
    }
    if(!scheduleMap.get(id).containsKey(subject)) {
        scheduleMap.get(id).put(subject, new ArrayList<String>());
    }
    scheduleMap.get(id).get(subject).add(sessionTime);
}
}
🌐
Blogger
javahungry.blogspot.com › 2020 › 06 › hashmap-to-arraylist.html
Convert HashMap to ArrayList in Java | Java Hungry
Conversion of HashMap Values into ArrayList In this method, we will create one ArrayList and add all the values into it using values() method of HashMap. import java.util.*; public class JavaHungry { public static void main(String args[]) { //Creating a HashMap Object HashMap<Integer,Integer> ...
🌐
Crunchify
crunchify.com › java j2ee tutorials › how to convert hashmap to arraylist in java?
How to convert HashMap to ArrayList in Java? • Crunchify
July 18, 2020 - package com.crunchify; /** * @author Crunchify.com */ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class CrunchifyHashmapToArrayList { public static void main(String... args) { HashMap<String, Integer> companyDetails = new HashMap<String, Integer>(); // create hashmap with keys and values (CompanyName, #Employees) companyDetails.put("eBay", 4444); companyDetails.put("Paypal", 5555); companyDetails.put("IBM", 6666); companyDetails.put("Google", 7777); companyDetails.put("Yahoo", 8
🌐
Stack Overflow
stackoverflow.com › questions › 29882073 › how-to-add-arraylist-in-hashmap-in-java-using-object-of-class
How to add arraylist in hashmap in java using object of class - Stack Overflow
April 26, 2015 - Copyimport java.util.*; public class Matrix extends Number{ private HashMap <Integer, ArrayList<Number>> hMap; public static int rows; public static int cols; public Matrix(int r,int c){ hMap = new HashMap <Integer, ArrayList<Number>>(); rows = r; cols = c; } public void fillMatrix () { ArrayList<Number> numarr = new ArrayList<Number>(); Scanner input = new Scanner(System.in); for(int i = 1; i <= rows; i++){ for(int j = 1; j <= cols; j++){ System.out.print("Enter Nomerator"); int nom = input.nextInt(); System.out.print("Enter Denomerator"); int denom = input.nextInt(); numarr.add(new Number(nom,denom)); } } for(int i = 1; i <= rows; i++){ for(int j = 1; j <= cols; j++){ hMap.put(j, numarr.get(i)); } } System.out.print(hMap); } } java · arraylist · hashmap ·