Java 8 Stream findFirst() and findAny()
In Java 8 Stream, the findFirst() returns the first element from a Stream, while findAny() returns any element from a Stream.
Java – How to convert a primitive Array to List
Code snippets to convert a primitive array int to a List. In Java 8, you can use the Stream APIs to do the boxing and conversion. You can’t use the…
How to sort an Array in java
Java example to show the use of Arrays.sort() to sort an Array. The code should be self-explanatory. Output Download Source Code $ git clone https://github.com/favtuts/java-core-tutorials-examples $ cd java-basic/array Reference Arrays…
How to copy an Array in Java
The methods described below are only applicable to one dimensional arrays. Arrays inherit methods from Object class, and Object.clone() is one of them. If you need to copy an Array…
Java – How to convert Array to Stream
In Java 8, you can either use Arrays.stream or Stream.of to convert an Array into a Stream. For object arrays, both Arrays.stream and Stream.of returns the same output. For object…
How to convert Array to List in Java
Java example to show you how to convert a Array to a List.
Java – How to declare and initialize an Array
Few Java examples to declare, initialize and manipulate Array in Java: Declares Array for primitive types, Declares array for classes or objects like String.class, Initialize array from method return an…
Java 8 – Convert a Stream to Array
In Java 8, we can use .toArray() to convert a Stream into an Array.
Java 8 – Convert a Stream to List
A Java 8 example to show you how to convert a Stream to a List via Collectors.toList Java8Example1.java Output Yet another example, filter a number 3 and convert it to…
Java 8 – Filter a null value from a Stream
Filter a null value from a Stream by using Stream.filter(x -> x!=null). Alternatively, filter with Objects::nonNull method reference