import java.util.*; class Algorithm { public int[] algorithm(int Num) { return Arrays.stream( Integer .toBinaryString(Num) // turn to binary .replaceAll(“(^0+|0+$)”, “”) … More
Tag: java8
[Java8] – How to check if all values in an array are equals?
public boolean isAllValuesEquals(int[] Arr ){ if ( Arrays.stream(Arr).distinct().count() == 1 ) { return true; } return false; }
An algorithm which shifts each element of the Array to the right N times.
import java.util.*; class Algorithm { public boolean isEmptyArray(int[] Arr ){ if ( Arr == null || Arr.length == 0) { … More
[Java 8] – Good Card : Default methods, Lambdas, Optional
[Java8] – Threads with lambdas
Example: @Test public void myMethod(){ Runnable run = () -> {System.out.println(“Execute Runnable”);}; new Thread(run).start(); } Console :
[Java 8] – New method Sort in List
Now you can use this method sort when you have a List Object and want sort this. If you only … More
[Java 8] – ForEach for interations
Below you can see an exemple how it works. @Test public void myTestWithForEachOnly(){ // Create the list and itens List<String> … More
Java : Switch
Use switch Statement when you know the possible values and you want do something for each any case. Example : … More
Java 8: Cool example to filter, compare and group by something using lambdas and streams
Example : In this example we take all foods are in a supermarket. We want only available products grouped by … More
Java 8 : How to use findFirst() in Streams API?
You can use this to do any interaction and break the process when find the first conditional. Example Optional<Plate> myFirstVegetarianOptional … More