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().
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);
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Map.html
Map (Java Platform SE 8 )
July 21, 2026 - If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. If the function returns null, the mapping is removed.
09:38
Java Tutorial #55 - Java Map Interface with Examples (Map Data ...
10:03
#94 Map in Java - YouTube
06:10
Java 8 streams map function tutorial - YouTube
3 map() Operation in Java Streams
01:27:21
Flatmap vs map in java 8 - Master the Difference! | Java Streams ...
01:56:59
Stream.map() + Java Generics – Everything You’ve Been Missing!
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
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 - If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. If the remapping function returns null, the mapping is removed.
CodingBat
codingbat.com › doc › java-functional-mapping.html
Java Functional Mapping
Java functional/lambda code is kind of magical, able to solve certain problem types with just 1 or 2 lines of code. In general, "mapping" is a strategy that starts with a collection of items, and runs a function on each item individually to compute a new value for that item.
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › Map.html
Map (Java SE 21 & JDK 21)
January 20, 2026 - Replaces the entry for the specified key only if currently mapped to the specified value. ... Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
CodingBat
codingbat.com › doc › java-map-introduction.html
Java Map Introduction
The most important Map function is map.get(key) which looks up the value for a key and returns it.
Scaler
scaler.com › home › topics › java stream map()
Java Stream map() - Scaler Topics
June 22, 2024 - The Java 8 Stream's map() method simply takes a stream of type X and returns another stream of type Y by applying the mapper function on the input stream elements and producing new stream elements of another type.
Codemia
codemia.io › home › knowledge hub › java is there a map function?
Java is there a map function? | Codemia
July 31, 2025 - One of the key aspects of Java is how it handles collections through the Java Collections Framework, which includes lists, sets, and maps. While Java does not have a built-in map function akin to those found in functional programming languages like JavaScript or Python, it does provide functionalities that allow similar operations through the Stream API, introduced in Java 8.
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); } }