I am not an expert but as per my analysis, I suggest not to start new features, until you have understood them & have strong reasons to use them. Otherwise I see some performance impact.
Here I will be putting my understanding as I get any.
Here I will be putting my understanding as I get any.
Just check simple program below using different ways & their results in next image, so understand the performance of new features before using them. And a humble request to the coders, don't mess up the project to use new features without understanding those, as every new feature comes with its cost -
import java.util.ArrayList;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.IntStream;
public class AnotherTest {
public static void main(String[] args) {
int range = 10000000;
int[] al = new int[range];
List<Integer> list = new ArrayList<Integer>();
ArrayList<Integer> alist = new ArrayList<Integer>();
long start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
al[i] = i;
}
int min = Integer.MAX_VALUE;
for(int i : al) {
if(i < min)
min = i;
}
System.out.println("Min : " + min);
System.out.println("Time taken by array : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
list.add(i);
}
min = Integer.MAX_VALUE;
for(int i : al) {
if(i < min)
min = i;
}
System.out.println("Min : " + min);
System.out.println("Time taken by list : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
alist.add(i);
}
min = Integer.MAX_VALUE;
for(int i : al) {
if(i < min)
min = i;
}
System.out.println("Min : " + min);
System.out.println("Time taken by array array list : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
al[i] = i;
}
System.out.println(IntStream.of(al).min().getAsInt());
System.out.println("Time taken by stream : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
al[i] = i;
}
IntSummaryStatistics is = IntStream.of(al).summaryStatistics();
System.out.println(is.getMin());
System.out.println(is.getAverage());
System.out.println("Time taken by IntSummaryStatistics : " + (System.currentTimeMillis()-start));
}
}
import java.util.ArrayList;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.IntStream;
public class AnotherTest {
public static void main(String[] args) {
int range = 10000000;
int[] al = new int[range];
List<Integer> list = new ArrayList<Integer>();
ArrayList<Integer> alist = new ArrayList<Integer>();
long start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
al[i] = i;
}
int min = Integer.MAX_VALUE;
for(int i : al) {
if(i < min)
min = i;
}
System.out.println("Min : " + min);
System.out.println("Time taken by array : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
list.add(i);
}
min = Integer.MAX_VALUE;
for(int i : al) {
if(i < min)
min = i;
}
System.out.println("Min : " + min);
System.out.println("Time taken by list : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
alist.add(i);
}
min = Integer.MAX_VALUE;
for(int i : al) {
if(i < min)
min = i;
}
System.out.println("Min : " + min);
System.out.println("Time taken by array array list : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
al[i] = i;
}
System.out.println(IntStream.of(al).min().getAsInt());
System.out.println("Time taken by stream : " + (System.currentTimeMillis()-start));
start = System.currentTimeMillis();
for(int i = 0; i < range; i++) {
al[i] = i;
}
IntSummaryStatistics is = IntStream.of(al).summaryStatistics();
System.out.println(is.getMin());
System.out.println(is.getAverage());
System.out.println("Time taken by IntSummaryStatistics : " + (System.currentTimeMillis()-start));
}
}