The java.util.stream is a sequence of elements supporting sequential and parallel aggregate operations.
The Stream.limit() method returns a Stream with elements of the source stream.
Java 8 stream limit method example
package com.w3schools;
import java.util.stream.Stream;
public class Test{
public static void main(String[] args) {
Stream.of("Jai", "Mahesh", "Vishal", "Naren", "Hemant")
.limit(3)
.forEach(System.out::println);
}
}
package com.w3schools;
import java.util.stream.Stream;
public class Test{
public static void main(String[] args) {
Stream.of("Jai", "Mahesh", "Vishal", "Naren", "Hemant")
.limit(3)
.forEach(System.out::println);
}
}
package com.w3schools; import java.util.stream.Stream; public class Test{ public static void main(String[] args) { Stream.of("Jai", "Mahesh", "Vishal", "Naren", "Hemant") .limit(3) .forEach(System.out::println); } }
Output
Jai
Mahesh
Vishal
Jai
Mahesh
Vishal
Jai Mahesh Vishal