Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我在 HashMap 中有几个对象:private HashMap <String,Object> hmap;
private HashMap <String,Object> hmap;
我想要做的是通过对象的变量(双)对这些对象进行排序。我该怎么做?我想我需要使用比较器,但我不知道如何使用它们。我应该将对象发送到数组吗?
我想您需要在单独的列表中进行排序。您将需要以下内容:
List<Object> values = new ArrayList<Object>(); values.addAll(hmap.values()); Collections.sort( values, new Comparator<Object>(){ public int compare(Object o1, Object o2){ //do specific comparison here });