Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
LongStream.Builder add() method in Java
The add() method of the LongStream.Builder class in Java adds an element to the stream being built. The method returns this builder.
The syntax is as follows
default LongStream.Builder add(long i)
Here, i is the input.
To use the LongStream.Builder class in Java, import the following package
import java.util.stream.LongStream;
Create LongStream.Builder and add some elements
LongStream.Builder builder = LongStream.builder();
Add some elements in the stream
builder.add(150L); builder.add(200L); builder.add(500L); builder.add(250L);
The following is an example to implement LongStream.Builder add() method in Java
Example
import java.util.stream.LongStream;
public class Demo {
public static void main(String[] args) {
LongStream.Builder builder = LongStream.builder();
builder.add(150L);
builder.add(200L);
builder.add(500L);
builder.add(250L);
builder.add(800L);
builder.add(650L);
builder.add(700L);
builder.add(900L);
builder.build().forEach(System.out::println);
}
}
Output
150 200 500 250 800 650 700 900
Advertisements
