如何使用Google Guava词典来按对象字段迭代对象列表?

时间:2012-08-26 20:44:08

标签: java list sorting object guava

类似的东西:

Ordering<Iterable<ImportXmlRecord>> comparator =
                Ordering.natural().lexicographical().onResultOf();

但按ImportXmlRecord字段排序?

1 个答案:

答案 0 :(得分:3)

不完全:

Ordering<Iterable<ImportXmlRecord>> comparator = Ordering.natural()
  .onResultOf(new Function<ImportXmlRecord, Whatever>() {
    public Whatever apply(ImportXmlRecord x) { return x.getWhatever(); }
  }.lexicographical();