Skip to content
Advertisement

Tag: java-8

Does the stream.spliterator() close the stream?

Does the stream.spliterator() implicitly closes the stream, or there is a need to explicitly close it afterwards? At first glance, it seems that the .spliterator() method closes the stream, but without calling stream.close(). At least if I close it straight away after the .spliterator() method is invoked, it seems not affection the spliterator operations. This question can be extended to

Way to parseInt without try-catch in Java 8?

Is there a better way to try to convert to int a string that can be or not an integer? Integer.parseInt(String value) will work well with “25” or “019” but not with “hello” or “8A”. In Java 8, we have optional values, for example: You do not need to check nulls, because the Optional wrapper expose useful methods to deal

Java Stream filter with regex not working

hope somebody can help me. I have a ArrayList of a Invoice class. What I’m trying to get is to filter this ArrayListand find the first element which one of its properties matches with a regex. The Invoiceclass looks like this: I’m filtering with this regex (\D+) in order to find if there is any value in the orderNumproperty that

try-with-resource – finally keyword error on Java 8 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 5 years ago. Improve this question

Prime number in java 8

I was trying to write a simple prime number program in Java 8. Below is the program. I wanted to reduce the code in isPrime() as well. Is there something that filters the elements from 2 to n/2, and then apply filter for n%i == 0 which would make isPrime irrelevant? Answer IntStream can be used to generate integer stream

Advertisement