Since Java 8, there are some standard options to do this in JDK:
Collection<E> in = ...
Object[] mapped = in.stream().map(e -> doMap(e)).toArray();
// or
List<E> mapped = in.stream().map(e -> doMap(e)).collect(Collectors.toList());
See java.util.Collection.stream() and java.util.stream.Collectors.toList().
GeeksforGeeks
geeksforgeeks.org › java › map-interface-in-java
Map Interface in Java - GeeksforGeeks
Use ConcurrentHashMap for thread-safe operations, or Collections.synchronizedMap() to make an existing map synchronized. ... import java.util.HashMap; import java.util.Map; public class Geeks{ public static void main(String[] args){ // Create a Map using HashMap Map<String, Integer> m = new HashMap<>(); // Adding key-value pairs to the map m.put("Geek1", 1); m.put("Geek2", 2); m.put("Geek3", 3); System.out.println("Map elements: " + m); } }
Published: August 31, 2026
Top answer 1 of 6
113
Since Java 8, there are some standard options to do this in JDK:
Collection<E> in = ...
Object[] mapped = in.stream().map(e -> doMap(e)).toArray();
// or
List<E> mapped = in.stream().map(e -> doMap(e)).collect(Collectors.toList());
See java.util.Collection.stream() and java.util.stream.Collectors.toList().
2 of 6
92
There is no notion of a function in the JDK as of java 6.
Guava has a Function interface though and the
Collections2.transform(Collection<E>, Function<E,E2>)
method provides the functionality you require.
Example:
// example, converts a collection of integers to their
// hexadecimal string representations
final Collection<Integer> input = Arrays.asList(10, 20, 30, 40, 50);
final Collection<String> output =
Collections2.transform(input, new Function<Integer, String>(){
@Override
public String apply(final Integer input){
return Integer.toHexString(input.intValue());
}
});
System.out.println(output);
Output:
[a, 14, 1e, 28, 32]
These days, with Java 8, there is actually a map function, so I'd probably write the code in a more concise way:
Collection<String> hex = input.stream()
.map(Integer::toHexString)
.collect(Collectors::toList);
06:33
Mastering Java Stream Map with a Simple Example - YouTube
Map In Java Tutorial - Map And HashMap In Java
10:10
Map and HashMap in Java - Full Tutorial - YouTube
10:31
Java hashmaps are easy! 🗺️ - YouTube
10:03
#94 Map in Java - YouTube
32:54
Map in Java || Map Interface Methods || Java Collection Framework ...
Which is faster: HashMap or TreeMap?
HashMap is faster for most operations because it uses hashing. TreeMap is slower as it maintains sorted order using a red-black tree.
wscubetech.com
wscubetech.com › resources › java › map
Map Interface in Java: Syntax, Methods, Examples & Uses
How to get all values from a Map?
Use values(), which returns a Collection of values.
wscubetech.com
wscubetech.com › resources › java › map
Map Interface in Java: Syntax, Methods, Examples & Uses
Can a Map have duplicate values?
Yes, values can be duplicated even if keys are unique.
wscubetech.com
wscubetech.com › resources › java › map
Map Interface in Java: Syntax, Methods, Examples & Uses
WsCube Tech
wscubetech.com › resources › java › map
Map Interface in Java: Syntax, Methods, Examples & Uses
August 12, 2026 - Learn Java Map Interface with simple examples. Explore Map methods, types, implementations like HashMap & TreeMap, key-value pairs, uses & common operations.
CodingBat
codingbat.com › doc › java-functional-mapping.html
Java Functional Mapping
In general, "mapping" is a strategy ... is an easy way to do mapping. As a first example, we'll use the "doubling" problem: given a list of integers, double each integer in the list....
Scaler
scaler.com › home › topics › java stream map()
Java Stream map() - Scaler Topics
June 22, 2024 - Now, let us consider one more example of the Java stream's map() method to extract the first 3 characters of a string in Java. ... In this example, we have used the substring() method in the map's mapper function to extract the first three characters from each of the strings in the list.
Tutorialspoint
tutorialspoint.com › java › java_map_interface.htm
Java - Map Interface
Following is an example to explain map functions using HashMap to add and remove elements to the map− · import java.util.HashMap; import java.util.Map; public class CollectionsDemo { public static void main(String[] args) { Map<String, String> m1 = new HashMap<>(); m1.put("Zara", "8"); m1.put("Mahnaz", "31"); m1.put("Ayan", "12"); m1.put("Daisy", "14"); System.out.println(); System.out.println(" Map Elements"); System.out.print("\t" + m1); m1.remove("Daisy"); System.out.println(" Map Elements"); System.out.print("\t" + m1); } }
Stackify
stackify.com › an-introduction-to-java-map-what-it-is-and-how-it-works
An Introduction to Java Map: What It Is and How It Works - Stackify
November 26, 2024 - As seen in the Map hierarchy, LinkedHashMap extends HashMap but maintains the order of insertion. This makes the function highly useful when the order of elements matters, such as in a caching system or tracking the sequence of user actions. Similar to HashMap, LinkedHashMap allows null keys and values. Let’s take a look at an example. Here, LinkedHashMap keeps track of the order of recent actions. import java.util.LinkedHashMap; import java.util.Map; public class LinkedHashMapExample { public static void main(String[] args) { Map<Integer, String> recentActions = new LinkedHashMap<>(); recentActions.put(1, "Login"); recentActions.put(2, "Viewed Profile"); recentActions.put(3, "Added to Cart"); System.out.println("Recent actions: " + recentActions); } }
Medium
medium.com › javarevisited › how-to-use-streams-map-filter-and-collect-methods-in-java-1e13609a318b
How to use map, filter, and collect methods in Java Stream? Example Tutorial | by javinpaul | Javarevisited | Medium
January 25, 2024 - Here is the Java program to implement whatever I have said in the above section. You can run this program in IDE or from the command line and see the result. You can also experiment with using more map() functions or more filter() calls to make the composition longer and more sophisticated.
Upgrad
upgrad.com › home › tutorials › software & tech › map in java
Map Interface in Java: Comprehensive Tutorial with Examples
August 14, 2025 - Master the Java Map interface with our detailed guide covering HashMap, TreeMap, and LinkedHashMap implementations, key methods, and practical code examples.
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › Map.html
Map (Java SE 11 & JDK 11 )
January 20, 2026 - Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. This method may be of use when combining multiple mapped values for a key. For example, to either create or append a String msg to a value mapping: