longs is an instance method of the Random class that is used to generate an infinite stream of random long values.
The Random class is defined in the java.util package. To import the Random class, check the following import statement.
import java.util.Random;
public LongStream longs()
The method has no parameters.
The method returns a stream of random long values.
import java.util.Random;public class Main{public static void main(String[] args) {Random random = new Random();random.longs().limit(10).forEach(System.out::println);}}
Random class.Random class.long values are generated using the longs method. We limit the stream to 10 and print the generated random values.