IntStream asLongStream() method in Java

Java 8ProgrammingObject Oriented Programming

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

 Live Demo

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
raja
Published on 26-Mar-2019 12:13:07
Advertisements