Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set<Entry<Producer,Price>> set = new TreeSet<>(new YourComparator);
- public class toto {
- public static void main(String[] args) throws IOException {
- toto main = new toto();
- HashMap<String, Integer> map = new HashMap<String, Integer>();
- map.put("producer1", 10);
- map.put("producer2", 56);
- map.put("producer3", 32);
- map.put("producer4", 253);
- map.put("producer5", 54);
- map.put("producer6", 12);
- System.out.println(map);
- TreeSet<Entry<String, Integer>> set = new TreeSet<Entry<String, Integer>>(main.new prodpriceComparator());
- set.addAll(map.entrySet());
- System.out.println(set);
- }
- public class prodpriceComparator implements Comparator<Entry<String, Integer>> {
- @Override
- public int compare(Entry<String, Integer> p1, Entry<String, Integer> p2) {
- return p1.getValue() - p2.getValue();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement