简体   繁体   English

Java PriorityQueue比较器

[英]Java PriorityQueue Comparator

Say I've implemented a HashMap in which characters get assigned an ArrayList of values. 假设我已经实现了一个HashMap,其中为字符分配了一个ArrayList值。

I've created a PriorityQueue of those characters in the HashMap, but I'd like to be able to remove the characters according to this priority: 我已经在HashMap中创建了这些字符的PriorityQueue,但是我希望能够根据此优先级删除这些字符:

{a, b, c} <- initial queue {a,b,c} <-初始队列

{a, b} Remove c since it contains a value in its ArrayList which determines it must be removed first. {a,b}删除c,因为它的ArrayList中包含一个值,该值确定必须首先删除它。

What would be the best way to go about this? 最好的方法是什么?

您将需要将键和值组合到单个对象中,并使用对这些新对象起作用的比较器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM