Skip to content

More realistic code example for Chaining Comparators #221

@authentictech

Description

@authentictech

In Learn -> Lambda Expressions -> Writing and Combining Comparators, in the section "Chaining Comparators" may I suggest a change to the code to make sorting by first name and last name more realistic?

Sorting of names is typically done by last name first and then first name after, rather than the other way around. So instead of what currently exists in the tutorial:

Comparator<User> byFirstNameThenLastName = byFirstName.thenComparing(byLastName);

... you will have:

Comparator<User> byLastNameThenFirstName = byLastName.thenComparing(byFirstName);

If the code that I suggest is changed and implemented in a program you will have realistically sorted names. As it is, the lesson still stands but it can be confusing to a beginner because the names will not actually be sorted correctly and it could seem like a programming error rather than a logical error.

This change would also require updating other code parts and text parts in this section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions