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.
🌐
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...
🌐
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 ·
🌐
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 ·
Find elsewhere
🌐
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); } }
🌐
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).
🌐
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.
🌐
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, ?
🌐
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?
🌐
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.
🌐
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
🌐
Dev.java
dev.java › learn › api › collections-framework › maps
Using Maps to Store Key Value Pairs - Dev.java
September 14, 2021 - This hierarchy is very simple and looks like the Set hierarchy, with SortedSet and NavigableSet. Indeed, a SortedMap shares the same kind of semantics as the SortedSet: a SortedMap is a map that keeps its key-value pairs sorted by their keys.
🌐
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.
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java hashmap › complete guide to java hashmap (with examples)
Complete Guide to Java HashMap (with Examples)
December 5, 2024 - The HashMap, part of the Java Collections framework, is used to store key-value pairs for quick and efficient storage and retrieval operations.