Java 8: How Lambda expression impacts -


i using java 8 new feature 'lambda expression' cool feature use. think helps developer simplify coding. have performance impact on application.

private void sortcities(list<string> cities){   //conventional way   collections.sort(cities, new comparator<string>() {      @override      public int compare(string s1, string s2) {         return s1.compareto(s2);      }   }); 

}

private void sortcities(list<string> cities){  //using lambda expression   collections.sort(cities, (s1, s2) -> s1.compareto(s2)); 

}

no, not. in particular case (without capturing arguments) lambda more performant comparator created once , reused, while anonymous class created each time call sortcities method.


Comments