I have question regarding Java Comparator. Or maybe you all have another Idea to solve this problems.
I have object called Product, below the Product Class looks like:
public class Product(){
private String productId;
private List categoryList;
//...setter and getter for category List
}
Then I have a list of Product, List. And I want to sort the list based on the category of Product:
Here example of the List:
{
Product = {
productId:10000567,
categoryList: {1002, 1003, 1007}
},
Product = {
productId:10000568,
categoryList: {1001, 1003, 1007}
},
Product = {
productId:10000569,
categoryList: {1001, 1004, 1007}
},
Product = {
productId:10000570,
categoryList: {1004, 1005, 1007}
}
}
I already try to use comparator, but I only can compare one value for one time.
Thanks for your response.
First, let your class Product implement the interface Comparable, then implement compareTo(), then sort the List with Collections.sort(myList);