I have a list of factories. Each factory has an item of its own and a list of other items from competitors.I need to sort the list of factories based on price of their items and also sort list of other items from competitors for each factory.What I am doing require to sort collection of factories and loop through all factories and sort collection of their competitors. I am wondering if there is any easier way to do it.Factoryclass Factory implements Comparator<Factory>{String item;double price;List<Competitor> competitors;@Override    public int compare(Factory o1, Factory o2) {        if (o1.getPrice() < o2.getPrice())            return -1;        if (o1.getPrice() > o2.getPrice())            return 1;        return 0;    }}Competitorclass Competitor implements Comparator<Competitor>{String facName;double price;@Overridepublic int compare(Competitor o1, Competitor o2) {        if (o1.getPrice() < o2.getPrice())            return -1;        if (o1.getPrice() > o2.getPrice())            return 1;        return 0;}SortCollection.sort(factoriesList); //sort list of factories//sort list of competitors of each factoryfor(int i=0;i<factoriesList.size();i++){   Collection.sort(factoriesList.getCometitors());}Sample resultFactory1 Item1 222  Com1 444 Com2 555Factory2 Item2 223  Com3 555 Com4 676Factory3 Item3 224  Com1 543 Factory4 Item4 225  Com9 322
Sorting a list and another list inside each item
java;sorting