Discuss / Java / `BigInteger`虽然没有极限,但`limit`方法只能传入`long`型,因此改成`BigInteger`,也没用:

`BigInteger`虽然没有极限,但`limit`方法只能传入`long`型,因此改成`BigInteger`,也没用:

Topic source
Stream<BigInteger> natual = Stream.generate(new Supplier<>() {
    private BigInteger n = BigInteger.ZERO;
    @Override
    public BigInteger get() {
        BigInteger result = n;
        n = n.add(BigInteger.ONE);
        return result;
    }
});
natual.limit(20).forEach(System.out::println);

  • 1

Reply