Sorting the order of sweets in decreasing order of their priority
Collections . sort ( v , new Comparator < Pair < Integer , Pair < Integer , Integer > > > ( ) { @ Override public int compare ( Pair < Integer , Pair < Integer , Integer > > a , Pair < Integer , Pair < Integer , Integer > > b ) { if ( a . first == b . first ) { if ( a . second . first == b . second . first ) { return b . second . second - a . second . second ; } return b . second . first - a . second . first ; } return b . first - a . first ; } } ) ;