this is easy in JavaScript. Not sure how to do this in Java:
Here's the hash table that's sent into displayItems:
Hashtable<Integer, String> items = new Hashtable<Integer, String>();
items.put(0, "Soda");
items.put(1, "Candy");
items.put(2, "Fruit");
Now here's what I'm trying to do, create a message based on that list:
public void displayItems(Hashtable<Integer, String> items) {
String message = "Please specify an item: ";
items.forEach((itemIndex, itemName) -> {
message += `${itemIndex}: ${itemName},`;
});
outputStream.print(message);
}
What I want to end up with printed to the stream for message is this:
"Please specify an item: 0: Soda, 1: Candy, 2: Fruit"
question from:
https://stackoverflow.com/questions/66055906/create-dynamic-templated-message-based-on-a-list 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…