Create a Pair class, that holds both the Integer and the String and then add multiple Pair objects to a List, which will be shuffled.

public class Pair {
  private Integer integer;

  private String string;

  //accessors
}

Then:

List<Pair> list = new ArrayList<Pair>();
//...add some Pair objects to the list
Collections.shuffle(list);
Answer from Konstantin Yovkov on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java collections › java map › get values and keys as arraylist from a hashmap
Get Values and Keys as ArrayList From a HashMap | Baeldung
March 7, 2025 - Map: k1 -> v1 k2 -> v2 k3 -> v3 index : 0, 1, 2 KeyList : k1, k2, k3 ValueList: v1, v2, v3 · The second scenario is relatively straightforward. Here, we aim to extract a key list and a value list from the provided map without retaining concern for the initial key-value pair associations.
Discussions

java - Create a list of key value objects - Stack Overflow
The answer on this thread: Java HashMap associative multi dimensional array can not create or add elements ... Frankly, I'm not sure how your answer pertains to the question. (I never down voted btw) 2013-08-24T03:59:46.837Z+00:00 ... It pertains to the question because it contains an example of how to solve this problem. The example shows how to create a HashMap and put multiple key-value ... More on stackoverflow.com
🌐 stackoverflow.com
data structures - What will store a Key-Value list in Java or an alternate of C# IDictionary in Java? - Stack Overflow
I am new to java development, I am from C# .net, developing android application. I am looking for Key-Value list to use in Java same as IDictionary in C#. Thanks More on stackoverflow.com
🌐 stackoverflow.com
January 5, 2015
java - What's the right data structure to combine iteration of key-value pairs, and iteration of values - Software Engineering Stack Exchange
I'm looking for a pre-existing or easy-to-build data structure available in Java, which can do these 2 things efficiently: Fetch all the values stored in the collection quickly. Iterate over the data structure to fetch each key and its value. Right now, I'm using a Pair. More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
November 2, 2022
How to fetch a List which is a "value" in Map?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
10
4
October 21, 2022
🌐
W3Schools
w3schools.com › java › java_hashmap.asp
Java HashMap
It is part of the java.util package and implements the Map interface. Instead of accessing elements by an index (like with ArrayList), you use a key to retrieve its associated value.
🌐
Dev.java
dev.java › learn › using-maps-to-store-key-value-pairs
Using Maps to Store Key Value Pairs
Watch & Listen · FAQ · Oracle University · Your first Java code · Using IDEs · Java Platform Evolution · Using JDK Preview Features · Language Basics · Object Oriented Programming · Generics, Lambda, and Pattern Matching · Annotations and Exceptions ·
🌐
Quora
quora.com › How-do-I-add-a-key-value-pair-in-ArrayList-in-Java
How to add a key value pair in ArrayList in Java - Quora
Answer (1 of 4): We can’t directly store key value pair. But we can achieve it through creating an ArrayList of user defined class, having two instance variables say key, value. Please refer the below example for understanding better - Otherwise, Hashmap, LinkedHashMap, TreeMap are the the data...
🌐
GeeksforGeeks
geeksforgeeks.org › java › keyvalue-class-in-java-tuples
KeyValue Class in JavaTuples - GeeksforGeeks
July 11, 2025 - KeyValue<type1, type2> kv = KeyValue.fromCollection(collectionWith_2_value); KeyValue<type1, type2> kv = KeyValue.fromArray(arrayWith_2_value); ... // Below is a Java program to create // a KeyValue tuple from Collection import java.util.*; import org.javatuples.KeyValue; class GfG { public static void main(String[] args) { // Creating KeyValue from List List<String> list = new ArrayList<String>(); list.add("GeeksforGeeks"); list.add("A computer portal"); KeyValue<String, String> kv = KeyValue.fromCollection(list); // Creating KeyValue from Array String[] arr = { "GeeksforGeeks", "A computer portal" }; KeyValue<String, String> otherKeyValue = KeyValue.fromArray(arr); System.out.println(kv); System.out.println(otherKeyValue); } }
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-all-linkedhashmap-key-value-pairs-to-list-in-java
How to Convert all LinkedHashMap Key-Value pairs to List in Java? - GeeksforGeeks
July 23, 2025 - // Java program to Convert all LinkedHashMap // Key-Value pairs to List import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; public class Sias { public static void main(String[] args) { // create LinkedHashMap LinkedHashMap<Integer, String> lhmap = new LinkedHashMap<Integer, String>(); // add elements in LinkedHashMap lhmap.put(1, "One"); lhmap.put(2, "Two"); lhmap.put(3, "Three"); lhmap.put(4, "Four"); lhmap.put(5, "Five"); // Create List 1 that store keys List<Integer> list1 = new ArrayList<Integer>(lhmap.keySet()); // display List 1 System.out.println("List 1 - " + list1); // Create List 2 that store values List<String> list2 = new ArrayList<String>(lhmap.values()); // display List 1 System.out.println("List 2 - " + list2); } } Output ·
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › hashmap-in-java-with-example
HashMap in Java With Examples
September 19, 2022 - HashMap is a Map based collection class that is used for storing Key & value pairs, it is denoted as HashMap<Key, Value> or HashMap<K, V>. HashMap in java, is similar to the Hashtable class except that it is unsynchronized and permits nulls(null values and null key).
🌐
Delft Stack
delftstack.com › home › howto › java › java key value pair
How to Implement Key Value Pair in Java | Delft Stack
February 12, 2024 - Initially, by importing the java.util package and specifically the Hashtable and Map classes. We declare and instantiate a Hashtable named keyValueTable, with explicit specifications that it will have String keys and Integer values.
🌐
Stack Abuse
stackabuse.com › java-how-to-get-keys-and-values-from-a-map
Java: How to Get Keys and Values from a Map
November 24, 2020 - Key (name) is: Billy, Value (age) is: 21 Key (name) is: David, Value (age) is: 24 Key (name) is: John, Value (age) is: 35 Key (name) is: Jane, Value (age) is: 19 · Java 8 introduces us to the forEach() method for collections. It accepts a BiConsumer<? super K, ?
🌐
Java Made Easy!
java-made-easy.com › java-collections.html
Java Collections - ArrayList and HashMap
One key corresponds to exactly one value, just like one username corresponds to one password.
🌐
Techie Delight
techiedelight.com › home › java › build a map from a list of keys and values in java
Build a Map from a List of keys and values in Java | Techie Delight
July 7, 2026 - This post will discuss how to build a Map from a List of keys and values in Java... Since Java 8, you can do this in a single line using Stream API.
🌐
Mrhaki
blog.mrhaki.com › 2021 › 01 › java-joy-transform-stream-of-strings-to.html
Java Joy: Transform Stream Of Strings To List Of Key Value Pairs Or Map - Messages from mrhaki
January 27, 2021 - */ @Override public Function<List<Map<String, String>>, List<Map<String, String>>> finisher() { return Function.identity(); } /** * @return Collector characteristic to indicate finisher method is identity function. */ @Override public Set<Characteristics> characteristics() { return Set.of(Characteristics.IDENTITY_FINISH); } } } Another solution could be to turn the Stream with values into a single Map. Each pair of values is a key/value pair in the resulting Map: package mrhaki.streams; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import ja
🌐
Coderanch
coderanch.com › t › 568613 › java › Adding-key-pairs-HashMap-ArrayList
Adding key/value pairs from a HashMap in to an ArrayList (Beginning Java forum at Coderanch)
February 26, 2012 - For the desired output we can assume that the productAttribute parameter value is "Computer". Current output of the addProduct ArrayList: Desired output of the addProduct ArrayList: I can't seem to figure out what I'm doing wrong. Any help would be greatly appreciated. ... So you have a map which maps a String to a list of Strings. And if I understand your example right, you want to mutate that into a list of lists of Strings, where each of the inner lists comprises a key of the map followed by the list it's mapped to?
🌐
Dev.java
dev.java › learn › api › collections-framework › maps
Using Maps to Store Key Value Pairs - Dev.java
September 14, 2021 - Multimap is a concept where a single key can be associated to more than one value. This concept is not directly supported in the Collections Framework. This feature may be useful though, and you will see later in this tutorial how you can create maps with values that are in fact lists of values. This pattern allows you to create multimap-like structures. As you already saw, Java SE 9 added methods to the List and Set interfaces to create immutable lists and sets.
🌐
Reddit
reddit.com › r/learnjava › how to fetch a list which is a "value" in map?
r/learnjava on Reddit: How to fetch a List which is a "value" in Map?
October 21, 2022 -

Hi folks, I hope you're doing awesome in life. I got stuck in a situation which is -

I've got a map which is of type -

Map<Integer,List<Integer>> m = new HashMap<>();

Now the thing is I want to create a (key,value) in map like -

(Key->Value)

(1->[1,2,3]),

(2 ->[2,3,4]),

(-1->[5,6,7]),

(0->[4])

And I want to add these key value pair in the Map by using the given below statement -

If(m.conatinskey(x)){ m.Put(x,m.get(x).add(any value)); ***** line ****** } else{ List<Integer> temp = new ArrayList<>(); temp.add(any integer value); m.add(temp); }

Now when I'm trying to execute the line statement I'm getting an error stating that my error has been simplified and I need verbose for better explanation but when I'm writing the statement as -

m.get(x).add(any value);

I am not getting any error . Can someone please let me know what's the issue as in my line statement I'm first trying to get the key and at thay key index I'm trying to add the element in the list ?

🌐
LabEx
labex.io › tutorials › java-how-to-create-a-map-of-key-value-pairs-in-java-413982
How to create a Map of key-value pairs in Java | LabEx
It is a part of the Java Collections Framework and is widely used in various programming scenarios. A Map is an object that stores a collection of key-value pairs. Each key in the Map must be unique, and it is used to access the corresponding value.