Rachha_Rachha Posted March 17, 2017 Report Share Posted March 17, 2017 Please give me inputs to achieve below sorting logic by using comparator. HashMap<String, Double> priceMap = {1044504144=2.99, 1044714260=15.99, 1042614005=559.99, 1041705834=139.99, 1040569574=74.99, 1018868750=11.99, 1012182945=9.99, 1016275930=23.99, 1043844296=2.99, 1041703106=19.99, 1041267899=3.99, 1045610202=9.99, 3252228=179.98} HashMap<String, Integer> reviewsCountMap = {1044504144=300, 1044714260=600, 1042614005=500, 1041705834=800, 1040569574=900, 1018868750=750, 1012182945=500, 1016275930=100, 1043844296=400, 1041703106=700, 1041267899=400, 1045610202=800, 3252228=200} Logic for product id display will follow: a. product id with Highest price; followed by b. product id with Least # of reviews; followed by c. product id with 2nd highest price; followed by d. product id with 2nd least # of reviews; and so on e.In case of products having the same price, the product with the less amount of views should display first f.In case of products having the same amount of reviews, the higher priced product should display first g.In case of products having the same price and number of reviews, the product with the higher product ID # will display first Quote Link to comment Share on other sites More sharing options...
BommaliNinnodhala Posted March 17, 2017 Report Share Posted March 17, 2017 @ICANWIN Quote Link to comment Share on other sites More sharing options...
GLK Posted March 17, 2017 Report Share Posted March 17, 2017 Use Comparator Chaining Sample example : http://www.codejava.net/java-core/collections/sorting-a-list-by-multiple-attributes-example Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.