Skip to content

ListSortingRecipes

pozil edited this page Nov 14, 2024 · 10 revisions

ListSortingRecipes Class

Demonstrates how to sort lists using the Comparator Interface

Group Collection Recipes

See AccountShippingCountryComparator

See AccountNumberOfEmployeesComparator

Methods

sortAccountsByShippingCountry(accounts)

Demonstrates how to sort a list of Account using Comparator Interface In this example we pass in the implementation class AccountShippingCountryComparator as a parameter to the sort method of a list. This method sorts Accounts by shipping address in ascending alphabetical order

Signature

public static void sortAccountsByShippingCountry(List<Account> accounts)

Parameters

Name Type Description
accounts List<Account> a list of accounts that will be sorted in place

Return Type

void


sortAccountsByShippingCountryInDescending(accounts)

Demonstrates how to sort a list of Account using Comparator Interface In this example we pass in the implementation class AccountShippingCountryComparator as a parameter to the sort method of a list. This method sorts Accounts by shipping address in descending alphabetical order

Signature

public static void sortAccountsByShippingCountryInDescending(List<Account> accounts)

Parameters

Name Type Description
accounts List<Account> a list of accounts that will be sorted in place

Return Type

void


sortAccountsByNumberOfEmployees(accounts)

Demonstrates how to sort a list of Account using Comparator Interface In this example we pass in the implementation class AccountNumberOfEmployeesComparator as a parameter to the sort method of a list.This method sorts Accounts by employee number in the ascending order

Signature

public static void sortAccountsByNumberOfEmployees(List<Account> accounts)

Parameters

Name Type Description
accounts List<Account> a list of accounts that will be sorted in place

Return Type

void

Clone this wiki locally