Stream is a convenient API which is introduced in Java 8 for aggregating values of aggregates such as arrays and collections.
In this article, I would like to introduce basic knowledge of Stream.
filter() returns some elements of this stream that match the given predicate.
count() method in stream API counts the elements in stream object.
articles.stream().filter(i -> i.isDraft()).count() //=> n
noneMatch() method is a method which takes argument as a Predicate and if none of element of stream matches the given Predicate, then it returns true otherwise false.
articles.stream().noneMatch(i -> i.isDraft())
Instream.range(int startInclusive, int endExclusive) returns a sequential ordered stream elements from startInclusive(inclusive) to endExclusive(exclusive) by an incremental step of 1.
java.util.Optional is a wrapper for a non-null value that may or may not contain a non-null value.
To get and use the value from
Optional, write it as follows:
article.ifPresent(value -> System.out.println("Article.id is" + article.getId()));
ifPresent(Consumer super T> action) method from the Optional class takes an action on the value contained in Optional object.
In this section, I would like to introduce how to add an original validation.
Initially, please create an annotation class:
Please add validation class:
Please define a validation message in Unicode.
native2ascii command can convert UTF-8 to Unicode or ASCII.
You should add a converted sentence to
You can apply your original validator to your code:
🖥 Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!