Java Stream map() Example
Tags: java
Published: 2021-12-09 11:17:54

The Java Stream _map()_ method is an intermediate operation.

## Java Stream map() Example
The Java Stream _map()_ method converts (maps) an element to another object. For instance, if you had a list of strings it could convert each string to lowercase, uppercase, or to a substring of the original string, or something completely else. 

**Here is a Java Stream map() example:**  If you have a List of String and you want to convert that to a List of Integer, you can use map() to do so.
```java
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
public class Main 
{
    public static void main(String[] args) 
    {
        List<String> listOfStrings = Arrays.asList("1", "2", "3", "4", "5");
         
        List<Integer> listOfIntegers = listOfStrings.stream()
                        .map(Integer::valueOf)
                        .collect(Collectors.toList());
         
        System.out.println(listOfIntegers);
    }
}
```
Output:
```

[1, 2, 3, 4, 5]
```
## Related Java Stream API's Examples
<ol><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-filter-example.html" target="_blank">Java Stream filter() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-map-example.html" target="_blank">Java Stream map() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-flatmap-example.html" target="_blank">Java Stream flatMap() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-distinct-example.html" target="_blank">Java Stream distinct() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-limit-example.html" target="_blank">Java Stream limit() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-peek-example.html" target="_blank">Java Stream peek() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-anymatch-example.html" target="_blank">Java Stream anyMatch() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-allmatch-example.html" target="_blank">Java Stream allMatch() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-nonematch-example.html" target="_blank">Java Stream noneMatch() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-collect-example.html" target="_blank">Java Stream collect() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-count-example.html" target="_blank">Java Stream count() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-findany-example.html" target="_blank">Java Stream findAny() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-findfirst-example.html" target="_blank">Java Stream findFirst() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-foreach-example.html" target="_blank">Java Stream forEach() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-min-example.html" target="_blank">Java Stream min() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-max-example.html" target="_blank">Java Stream max() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-reduce-example.html" target="_blank">Java Stream reduce() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2021/11/java-stream-toarray-example.html" target="_blank">Java Stream toArray() Example</a></li></ol>