There are various ways to achieve this. Here are three.

    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    System.out.println("using entrySet and toString");
    for (Entry<String, String> entry : map.entrySet()) {
        System.out.println(entry);
    }
    System.out.println();

    System.out.println("using entrySet and manual string creation");
    for (Entry<String, String> entry : map.entrySet()) {
        System.out.println(entry.getKey() + "=" + entry.getValue());
    }
    System.out.println();

    System.out.println("using keySet");
    for (String key : map.keySet()) {
        System.out.println(key + "=" + map.get(key));
    }
    System.out.println();

Output

using entrySet and toString
key1=value1
key2=value2
key3=value3

using entrySet and manual string creation
key1=value1
key2=value2
key3=value3

using keySet
key1=value1
key2=value2
key3=value3
Answer from Stefan Dollase on Stack Overflow
🌐
Salesforce
trailhead.salesforce.com › trailblazer-community › feed › 0D54V00007T4LjLSAV
Working with Map<String, Map<>> - Trailhead - Salesforce
Skip to main content · The online Trailblazer Community becomes read-only Oct 30, 2026, as we move new community conversations to Slack. Read the FAQ
🌐
Baeldung
baeldung.com › home › java › java collections › java map › map to string conversion in java
Map to String Conversion in Java | Baeldung
January 8, 2026 - Learn how to convert a Map to a String and the other way around using both core Java methods and third-party libraries.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › how-to-insert-data-in-the-map-of-strings
How to insert data in the map of strings? - GeeksforGeeks
July 23, 2025 - Return Value: It returns an iterator pointing to the new element in the map. ... // C++ program to store the string as // the map value #include <iostream> #include <map> using namespace std; // Driver code int main() { // Get the Strings string s = "abc"; string s1 = "bca"; string s2 = "cba"; // Declare map with both value // and key having string data_type map<string, string> m; // Insert the string in the map m.insert(pair<string, string>(s1, s)); m.insert(pair<string, string>(s, s2)); // Print the elements stored // in the map for (auto itr = m.begin(); itr != m.end(); ++itr) { cout << itr->first << '\t' << itr->second << '\n'; } return 0; }
🌐
Vogella
vogella.com › tutorials › JavaMap › article.html
Using the map datastructures like HashMap and ConcurrentHashMap in Java
September 25, 2024 - Map<String, String> map = Map.of("key1", "value1", "key2", "value2");
🌐
O'Reilly
oreilly.com › library › view › c-cookbook › 0596007612 › ch06s07.html
6.6. Mapping strings to Other Things - C++ Cookbook [Book]
November 8, 2005 - #include <iostream> #include <map> #include <string> using namespace std; int main() { map<string, string> strMap; strMap["Monday"] = "Montag"; strMap["Tuesday"] = "Dienstag"; strMap["Wednesday"] = "Mittwoch"; strMap["Thursday"] = "Donnerstag"; strMap["Friday"] = "Freitag"; strMap["Saturday"] = "Samstag"; // strMap.insert(make_pair("Sunday", "Sonntag")); strMap.insert(pair<string, string>("Sunday", "Sonntag")); for (map<string, string>::iterator p = strMap.begin(); p != strMap.end(); ++p ) { cout << "English: " << p->first << ", German: " << p->second << endl; } cout << endl; strMap.erase(strMap.find("Tuesday")); for (map<string, string>::iterator p = strMap.begin(); p != strMap.end(); ++p ) { cout << "English: " << p->first << ", German: " << p->second << endl; } }
Authors: D. Ryan StephensChristopher DigginsJonathan TurkanisJeff Cogswell
Published: 2005
Pages: 594
🌐
Alex MacArthur
macarthur.me › posts › creating-a-map-method-for-objects-strings-sets-and-maps
Creating a .map() Method for Objects, Strings, Sets, and Maps | Alex MacArthur
March 4, 2023 - This one’s a bit simpler than our Object map. Turn the target string into an array, map() over it as per usual, and turn it back into a string:
Find elsewhere
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › string › map string
Apply a mapping function to each character in a JavaScript string - 30 seconds of code
February 27, 2024 - When working with arrays, the mapping ... itself. When working with strings, the mapping function should expect the current character, the index of the current character and the string itself....
Top answer
1 of 3
5

Using a map like that obfuscates the parameters, making it so developers have to read the method to know what parameters to use. Worse, these kinds of maps are case sensitive. I would strongly recommend you don't do this. If you have enough parameters that you'd want to do this, make a wrapper or Data Transfer Object.

2 of 3
2

Just some general notes:

  1. sfdcfox's answer is, as always, brilliant. Using a map like that isn't a great idea, and I'd go so far as to say it's a bad idea.
  2. I like your desire to let other developers know what the parameters are, but I think the right way to solve this is with proper documentation. Apex-recipes (https://github.com/trailheadapps/apex-recipes) uses the npm package "@cparra/apexdocs" to generate standardized markdown files for classes. The per-method documentation block looks like this:

/**

  • @description The doLoad method is required by the CacheBuilder interface
  • This method needs to return an Object - and that's the key to the Cache
  • builder interface - You must have this method return a single Object that
  • is either calculated by this method, or returned from the Cache by the
  • key
  • @param key String used to help generate the Cache Key
  • @return Object This object should be casted at the call location
  • @group Platform Cache Recipes
  • @see CanTheUser
  • @example Account[] accounts = (Account[]) Cache.Session.get(PlatformCacheBuilderRecipes.class, 'myAccounts') */ public Object doLoad(String key) {

So that's not rendering great, but those bullet points are *'s

Apexdocs understands certain tags, like @description and when run it generates docs like this markdown.

---
layout: default
---
# PlatformCacheBuilderRecipes class

demonstrates how to use the Cache.CacheBuilder Interface

---
## Methods
### `doLoad(String key)` → `Object`

The doLoad method is required by the CacheBuilder interface This method needs to return an Object - and that&apos;s the key to the Cache builder interface - You must have this method return a single Object that is either calculated by this method, or returned from the Cache by the key

#### Parameters
|Param|Description|
|-----|-----------|
|`key` |    String used to help generate the Cache Key |

#### Return

**Type**

Object

**Description**

`Object` This object should be casted at the call location

#### Example
```java
Account[] accounts = (Account[]) Cache.Session.get(PlatformCacheBuilderRecipes.class, 'myAccounts')
```

---

Generating and making this kind of documentation available makes it easy for your third party developers to consume your methods, and readily identify what order the parameters are in.

🌐
Baeldung
baeldung.com › home › java › java string › converting string or string array to map in java
Converting String or String Array to Map in Java | Baeldung
January 8, 2024 - In this method, we use StringTokenizer() to split the String by the delimiter (comma in this case) and then use split(“=”) to extract the key and value. The resulting key-value pairs are added to the Map.
🌐
RTLCSS
rtlcss.com › learn › usage-guide › string-map › index.html
String Map | RTLCSS
September 18, 2023 - String maps is an array of map objects, where each defines a mapping between directional strings.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Converting String or String Array to Map in Java - Java Code Geeks
October 10, 2023 - In this example, We start by defining the input string containing key-value pairs and the delimiter ",". Next, we create a HashMap to store the key-value pairs. We then use StringTokenizer to split the input string into tokens based on the delimiter. Finally, we iterate through the tokens, split each token into key-value pairs using the "=" character, and add them to the map.
🌐
W3Schools
w3schools.com › java › java_hashmap.asp
Java HashMap
A HashMap stores items in key/value pairs, where each key maps to a specific value.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › converting map to map in java
Converting Map to Map in Java | Baeldung
January 8, 2024 - As the test above shows, although result2 is in type Map<String, String>, one value in the map isn’t a string. This could lead to unexpected issues in further processes. So next, let’s see how to achieve a safe conversion. We can build a checkAndTransform() method to perform a safe conversion: Map<String, String> checkAndTransform(Map<String, Object> inputMap) { Map<String, String> result = new HashMap<>(); for (Map.Entry<String, Object> entry : inputMap.entrySet()) { try { result.put(entry.getKey(), (String) entry.getValue()); } catch (ClassCastException e) { throw e; // or a required error handling } } return result; }
🌐
Cplusplus
cplusplus.com › forum › general › 211386
Map to String - C++ Forum
March 19, 2017 - So I am given the function where I am given a map that has a string key and a long value, and it is a pointer of m. I know how to print a map, but I am not sure on how to go about for taking the map and making it into a single string.
🌐
Stack Overflow
stackoverflow.com › questions › 71995190 › how-to-add-mapstring-string-in-collectionmapstring-string
java - How to add Map<String,String> in Collection<Map<String,String>> - Stack Overflow
Either declare a map first then add it to the collection: CopyMap<String, String> map = new HashMap<>(); Collection<Map<String, String>> collection = new HashSet<>(); collection.add(map);
🌐
Tcl Wiki
wiki.tcl-lang.org › page › string+map
string map - the Tcler's Wiki!
Cut down the verbosity of string map by using the same name to obtain a value from a local variable and to map that value into the string, providing default delimiters, and by automatically quoting values with list.