I am using JDK 1.7 for my project. I have come across Huddle. I have an ArrayList of objects which have two properties: price (decimal) and product name (String). I need to sort the ArrayList, first by price and then by product name. I've tried to use the Java comparator, but I can only sort by one property. Here is my code:
private static class PriceComparator implements Comparator<Product>{
@Override
public int compare(Product p1, Product p2) {
return (p1.getPrice() > p2.getPrice() ) ? -1: (p1.getPrice() < p2.getPrice()) ?
1:0 ;
}
}
This code only sort price, and not name.
Please i would apprecaite your help and example.
Thanks Ish