Method References - Lambda Expressions In Java 8: Tutorial 8

preview_player
Показать описание
In this tutorial I go over a more compact, easy-to-read, and faster form of writing lambda expressions known as method references.

Thanks for watching!!!! Comment, like, and subscribe

My Links:

These tutorials take a lot of time out of my day. If you feel obligated to make a donation, there's a link on my channel. Thanks!
Рекомендации по теме
Комментарии
Автор

I chose to watch this to get an understanding of method references...I didn't need the whole performance spiel

tcastock
Автор

List<String> list = Arrays.asList("Toby", "Anna", "Leroy", "Alex");
        List<String> filtered = new ArrayList<>();
                long start1 = System.currentTimeMillis();
        list.stream().filter(n -> n.length() ==
        long end1 = System.currentTimeMillis();
       
       
        long start = System.currentTimeMillis();
        for (String name: list){
           if (name.length() == 4) filtered.add(name);
        }
        Collections.sort(filtered);
        Iterator<String> iter = filtered.iterator();
       
        for(int i = 0; i < 2; i++) if(iter.hasNext())
        long end = System.currentTimeMillis();
       

MrCodix
Автор

Hello! Try to swap these two blocks and you will see that system.out::println will be slower :))

tarasg
Автор

0 milliseconds for old fashioned java 7 way, bloody 116 ms for java 8 "fast" way

MrCodix
Автор

54 ms when I comment old fashioned way out (with the iterator)

MrCodix