I am using Java application.
Here is my map
{
"name": "John",
"address": "US"
}
Code block:
Map<String, Object> response = new HashMap<>();
final List<String> TYPES = List.of("name", "gender", "age");
String display = "text"; // text, password
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (TYPES.contains(entry.getKey())) {
String result = (String) entry.getValue();
if (display.equals("text"))) {
result = // do some manipulation
} else if (display.equals("password")) {
result = // do some manipulation
}
response.put(entry.getKey(), result);
} else {
response.put(entry.getKey(), entry.getValue());
}
}
Based on the display type, I get different responses. Above code is working fine. Is it more efficient way to do this code using Java Streams?