- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream mapToInt() method in Java
The mapToInt() function of the DoubleStream class returns an IntStream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows
IntStream mapToInt(DoubleToIntFunction mapper)
Here, mapper is a stateless function to apply to each element. The DoubleToIntFunction is a function that accepts a double-valued argument and produces an int-valued result.
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
The following is an example to implement DoubleStream mapToInt() method in Java
Example
import java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(45.8, 78.9, 67.8, 59.1); IntStream intStream = doubleStream.mapToInt(a -> (int)a); intStream.forEach(System.out::println); } }
Output
45 78 67 59
Advertisements