- 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
LongStream boxed() method in Java
The boxed() method of the LongStream class returns a Stream consisting of the elements of this stream, each boxed to a Long.
The syntax is as follows.
Stream<Long> boxed()
Here, Stream represents a sequence of elements. To use the LongStream class in Java, import the following package.
import java.util.stream.LongStream;
Create an IntStream and add some elements in a range using the range() method.
LongStream intStream = LongStream.range(20800L, 20805L);
Now, use the boxed() method
Stream<Long> s = intStream.boxed();
The following is an example to implement LongStream boxed() method in Java.
Example
import java.util.stream.Stream; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream intStream = LongStream.range(20800L, 20805L); Stream<Long> s = intStream.boxed(); s.forEach(System.out::println); } }
Output
20800 20801 20802 20803 20804
Advertisements