-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
9
A DESCRIPTION OF THE REQUEST :
Lambdas expression taking long time than using anonymous class.
please check attached code and output;
In output please check time differences ;
So why i need to use lambdas ?
JUSTIFICATION :
Lambdas expression taking long time
ACTUAL -
11:58:58.892 - thread: main
[A, APIs, APIs, APIs, However, In, Java, Java, a, a, a, an, and, and, are, be, become, but, button, can, classes, click, code, concise, consistency, consistent, could, e
asier, every, feature, function, handler, have, if, implementing, in, includes, is, isnt, it, it, its, just, language, languages, large, marginally, mess, more, more, mo
re, objects, of, of, of, one, or, other, particular, powerful, register, similar, simpler, simplicity, spawn, strength, such, swaths, take, that, that, their, those, thr
ead, to, to, to, unmaintainable, unpleasant, use, would, written, yields]
11:58:58.901 - thread: main
-------------------------------------------------------------
11:58:58.901 - thread: main
[A, APIs, APIs, APIs, However, In, Java, Java, a, a, a, an, and, and, are, be, become, but, button, can, classes, click, code, concise, consistency, consistent, could, e
asier, every, feature, function, handler, have, if, implementing, in, includes, is, isnt, it, it, its, just, language, languages, large, marginally, mess, more, more, mo
re, objects, of, of, of, one, or, other, particular, powerful, register, similar, simpler, simplicity, spawn, strength, such, swaths, take, that, that, their, those, thr
ead, to, to, to, unmaintainable, unpleasant, use, would, written, yields]
11:58:58.990 - thread: main
-------------------------------------------------------------
---------- BEGIN SOURCE ----------
import java.util.*;
import java.time.LocalTime;
public class HelloWorld{
public static void main(String []args){
String ss="strength of Java is its simplicity and consistency A language can become an unmaintainable mess if it includes every feature that yields marginally more concise code However in those other languages it isnt just easier to spawn a thread or to register a button click handler large swaths of their APIs are simpler more consistent and more powerful In Java one could have written similar APIs that take objects of classes implementing a particular function but such APIs would be unpleasant to use";
System.out.println("-------------------------------------------------------------");
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
List<String> ll=Arrays.asList(ss.split(" "));
Collections.sort(ll,new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareTo(o2);
};
});
System.out.println(ll);
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
System.out.println("-------------------------------------------------------------");
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
List<String> l=Arrays.asList(ss.split(" "));
Collections.sort(l,(a,b)->a.compareTo(b));
System.out.println(l);
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
System.out.println("-------------------------------------------------------------");
}
}
---------- END SOURCE ----------
Lambdas expression taking long time than using anonymous class.
please check attached code and output;
In output please check time differences ;
So why i need to use lambdas ?
JUSTIFICATION :
Lambdas expression taking long time
ACTUAL -
11:58:58.892 - thread: main
[A, APIs, APIs, APIs, However, In, Java, Java, a, a, a, an, and, and, are, be, become, but, button, can, classes, click, code, concise, consistency, consistent, could, e
asier, every, feature, function, handler, have, if, implementing, in, includes, is, isnt, it, it, its, just, language, languages, large, marginally, mess, more, more, mo
re, objects, of, of, of, one, or, other, particular, powerful, register, similar, simpler, simplicity, spawn, strength, such, swaths, take, that, that, their, those, thr
ead, to, to, to, unmaintainable, unpleasant, use, would, written, yields]
11:58:58.901 - thread: main
-------------------------------------------------------------
11:58:58.901 - thread: main
[A, APIs, APIs, APIs, However, In, Java, Java, a, a, a, an, and, and, are, be, become, but, button, can, classes, click, code, concise, consistency, consistent, could, e
asier, every, feature, function, handler, have, if, implementing, in, includes, is, isnt, it, it, its, just, language, languages, large, marginally, mess, more, more, mo
re, objects, of, of, of, one, or, other, particular, powerful, register, similar, simpler, simplicity, spawn, strength, such, swaths, take, that, that, their, those, thr
ead, to, to, to, unmaintainable, unpleasant, use, would, written, yields]
11:58:58.990 - thread: main
-------------------------------------------------------------
---------- BEGIN SOURCE ----------
import java.util.*;
import java.time.LocalTime;
public class HelloWorld{
public static void main(String []args){
String ss="strength of Java is its simplicity and consistency A language can become an unmaintainable mess if it includes every feature that yields marginally more concise code However in those other languages it isnt just easier to spawn a thread or to register a button click handler large swaths of their APIs are simpler more consistent and more powerful In Java one could have written similar APIs that take objects of classes implementing a particular function but such APIs would be unpleasant to use";
System.out.println("-------------------------------------------------------------");
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
List<String> ll=Arrays.asList(ss.split(" "));
Collections.sort(ll,new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareTo(o2);
};
});
System.out.println(ll);
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
System.out.println("-------------------------------------------------------------");
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
List<String> l=Arrays.asList(ss.split(" "));
Collections.sort(l,(a,b)->a.compareTo(b));
System.out.println(l);
System.out.println(LocalTime.now() + " - thread: " + Thread.currentThread().getName());
System.out.println("-------------------------------------------------------------");
}
}
---------- END SOURCE ----------