Example: Steam map()
import java.util.ArrayList;
import java.util.List;
public class Java8StreamMapExample {
public static void main(String... args) {
List arrayList = new ArrayList<>();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
arrayList.add(5);
arrayList.add(6);
arrayList.add(7);
arrayList.add(8);
arrayList.add(9);
arrayList.add(10);
arrayList.stream().map(no -> no * 5).forEach(System.out::println);
}
}
Output:
5 10 15 20 25 30 35 40 45 50
In the above example we have made use of the stream map method to calculate the calculation table of 5 using an ArrayList.
Have Questions? Post them here!
More Posts related to Java,
- How to Get List of All Country Codes in Java Using Locale Class
- Unsupported major.minor version 52.0 in java
- Java - How to set custom thread name?
- Get the current timestamp in Java
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- [fix] NullPointerException Cannot Invoke findById because Repository is null - Java Spring
- java: unclosed string literal [Error]
- Convert Java Byte Array to String with code examples
- Error: Can not find the tag library descriptor for
- Java 8 - Convert List to Map Examples
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Fix java.net.ProtocolException: Invalid HTTP method
- Java: Convert Stream to List
- Java equals method - Tutorial
- List of Java JDBC Database Driver Jars, Classes and URLs Details
- Read YAML file Java Jackson Library
- How to display Java Date Time timezone GMT/UTC offset using SimpleDateFormat
- List of Java Keywords
- Enable JSON Pretty Print in Java Jackson
- How to Word-Warp Console logs in IntelliJ
- Convert Map to List in Java 8 using Stream API
- Create a Directory using Java Code
- Ways to Convert Integer or int to Long in Java
- [Program] How to read three different values using Scanner in Java
- Java JDBC Example with Oracle Database Driver Connection
More Posts:
- Test internet speed using macOS Terminal command - MacOS
- [Solved] Dynamic Web Module 3.0 requires Java 1.6 or newer Mac OSX - Mac-OS-X
- Save cURL Command Output to a external file - cURL
- [Android Studio] Could not automatically detect an ADB binary - Android-Studio
- How to Convert CSV file to SQL Script using Notepad++ - NotepadPlusPlus
- [Solved] SharePoint System.IO.FileNotFoundException was unhandled - SharePoint
- How to check if a String contains substring or a word using javaScript - JavaScript
- Disable Control Scroll Zoom-in and Zoom-out in Notepad++ - NotepadPlusPlus