Mapping a Collection by two fields in java
<p>I just need help with this one part of my homework. the instructions are to
Use lambdas and streams to map each Invoice to its PartDescription and Quantity,
sort the results by Quantity, then display the results.</p>

<p>i have most of the code but what im confused about is how do i map by part description AND quantity. I understand how to map by just one field but not two. here is my code. The last part is where i start to need the help. right now it is just mapped by part description but i need to map by part description AND quantity</p>

<pre><code>import java.util.*;
import java.util.function.Function;

public class ProcessInvoices {

    public static void main(String[] args) {

        //initialize array of invoice objects
        Invoice[] invoices = {
                new Invoice(83 , "Electric sander", 7 , 57.89),
                new Invoice(24, "Power saw", 18, 99.99),
                new Invoice(7, "Sledge hammer", 11, 21.50),
                new Invoice(77, "Hammer", 76, 11.99),
                new Invoice(39, "Lawn mower", 3, 79.50),
                new Invoice(68, "Screwdriver" ,106, 6.99),
                new Invoice(56, "Jig saw", 21 ,11.00),
                new Invoice(3, "Wrench" ,34, 7.50)};

        List&lt;Invoice&gt; list = Arrays.asList(invoices);
        System.out.println("List of Invoice items: ");
        list    .stream()
                .forEach(System.out::println);

        //Fucnction for getting part information for sorting
        Function&lt;Invoice, String&gt; byPartDescription = Invoice::getPartDescription;
        Function&lt;Invoice, Double&gt; byPrice = Invoice::getPrice;
        Function&lt;Invoice, Integer&gt; byQuantity = Invoice::getQuantity:;

        //Comparator for invoice objects by part descsriprion
        Comparator&lt;Invoice&gt; justPartDesc =
                Comparator.comparing(byPartDescription);

        //sort by part description
        System.out.printf("%nInvoice objects in ascending order by part description: %n");
        list    .stream()
                .sorted(justPartDesc)
                .forEach(System.out::println);

        //Comparator for invoice by price
        Comparator&lt;Invoice&gt; justPrice = Comparator.comparing(byPrice);
        //sort by price
        System.out.printf("%nInvoice Obejects sorted in ascending order by price: %n");
        list    .stream()
                .sorted(justPrice)
                .forEach(System.out::println);

        Comparator&lt;Invoice&gt; justQuantity = Comparator.comparing(byQuantity);

        //map invoice to part descripiton and quantity
        System.out.printf("%nInvoice objects mapped to part descripton and Quantity");
        list    .stream()
                .map(Invoice::getPartDescription)
                .distinct()
                .sorted()
                .forEach(System.out::println);

    }
}
</code></pre>