Java Introducing Lambdas

Jack Chaffin
PLUS
Jack Chaffin
Courses Plus Student 3,326 Points

Collections.sort method not being used in lambdas?

So... I don't quite understand why we're putting the whole collections.sort method in either of the lambda examples. Java doesn't seem to be using them. Here's my code:

package com.teamtreehouse.lambdas;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {

    public static void usingAnonymousInlineClass() {
        List<Book> books = Books.all();
//        Collections.sort(books, new Comparator<Book>() {
//            @Override
//            public int compare(Book b1, Book b2) {
//                return b1.getTitle().compareTo(b2.getTitle());
//            }
//        });

        for (Book book : books) {
            System.out.println(book);
        }
    }

    public static void usingLambdasInLongForm() {
        List<Book> books = Books.all();
        Collections.sort(books, (Book b1, Book b2) -> {
            return b1.getTitle().compareTo(b2.getTitle());
        });
        books.forEach(book -> System.out.println(book));
    }

    public static void usingLambdasInShortForm() {
        List<Book> books = Books.all();
        //Collections.sort(books, (b1, b2) -> b1.getTitle().compareTo(b2.getTitle()));
        books.forEach(book -> System.out.println(book));
    }

    public static void main(String[] args) {
        usingLambdasInShortForm();
    }
}

Notice how I commented out the Collections.sort lambda method in usingLamdasInShortForm()? I did that because the IDE was giving me an indication that the code wasn't being executed. Commenting it out here's the results in the terminal:

"C:\Program Files\Amazon Corretto\jdk11.0.10_9\bin\java.exe" "-javaagent:C:\Program >Files\JetBrains\IntelliJ IDEA Community Edition >2020.3.2\lib\idea_rt.jar=54466:C:\Program Files\JetBrains\IntelliJ IDEA Community >Edition 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath >C:\Users\jchaf\Downloads\lambdas\lambdas-start\Lambdas\out\production\Lambdas com.teamtreehouse.lambdas.Main

Book{mTitle='Functional Programming in Java', mAuthor='Venkat Subramaniam', mPublicationDate=2014}

Book{mTitle='Clean Code', mAuthor='Robert C. Martin', mPublicationDate=2008}

Book{mTitle='Java Generics and Collections', mAuthor='Maurice Naftalin and Philip Wadler', mPublicationDate=2008}

Book{mTitle='Effective Java', mAuthor='Joshua Bloch', mPublicationDate=2008}

Book{mTitle='Pragmatic Unit Testing in Java 8 with JUnit', mAuthor='Jeff Langr', mPublicationDate=2015}

Book{mTitle='JavaFX Essentials', mAuthor='Mohamed Taman', mPublicationDate=2015}

Process finished with exit code 0

Why?