1

I use Guava multimap to store data from a textfile. The textfile data format is like:

p1 10
p2 30
p3 40
p1 20
p2 50
p3 60
..
..

First column is the key and second is the value. I want to sort the score(value) from highest to lowest, but have no idea how to sort a multimap.. or is there a better storage to store that kind of data?

What other thing I thought is making two arraylist, one for name and another for scores, though

I don't know it is possible to link two lists.

list1 = {p1,p2,p3}
list2 = {10, 20, 30, 40, 50, 60}

p1 index directing 10 and 20. Is this kind of thing possible?

sblck
  • 137
  • 1
  • 6
  • 14
  • SortedMap< String, SortedSet< String >> map = new TreeMap<>(); If you want more tell me... – Aubin Nov 24 '12 at 12:46
  • See [Having a Multimap sorted on keys only in Java](http://stackoverflow.com/questions/5501468/having-a-multimap-sorted-on-keys-only-in-java) – Reimeus Nov 24 '12 at 12:48

1 Answers1

1

You can try something like this:-

 public static ImmutableMultimap<Integer, MyObject> indexOnScore(Iterable<MyObject> i) {
  List<MyObject> sorted = Ordering.natural().onResultOf(myObjectToScore())
  .sortedCopy(i);
   return Multimaps.index(sorted, myObjectToScore());
}

Another option might be to create a TreeMultimap and use Ordering.arbitrary() as the Comparator for the values.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331