Example: Stream 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.
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- Run Scripting Language (JavaScript, Python, Groovy, Ruby) in Java - Java
- Fix: error: could not find `Cargo.toml` in Users or any parent directory - Rust
- W3 HTML validator warning Unable to Determine Parse Mode - Html
- Remove All Spaces in a File using Notepad++ - NotepadPlusPlus
- How to set background color for android layout pragmatically using java and through xml - Android
- Portable Notepad++ for windows - NotepadPlusPlus
- Check Android Studio App is M1/M2 Chip based post installation - Android-Studio
- How to Enable spellcheck Notepad++ - NotepadPlusPlus