- Trending Categories
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
IntStream asLongStream() method in Java
The asLongStream() method of the IntStream class returns a LongStream consisting of the elements of this stream, converted to long.
The syntax is as follows
LongStream asLongStream()
Create an IntStream and add some elements in the Stream
IntStream intStream = IntStream.of(30, 40, 60, 70, 90, 110, 140, 150);
Now, use the asLongStream() method to convert it to long
LongStream longStream = intStream.asLongStream();
The following is an example to implement IntStream asLongStream() method in Java
Example
import java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(30, 40, 60, 70, 90, 110, 140, 150); LongStream longStream = intStream.asLongStream(); longStream.forEach(System.out::println); } }
Output
30 40 60 70 90 110 140 150
Advertisements