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?

2
  • SortedMap< String, SortedSet< String >> map = new TreeMap<>(); If you want more tell me... Commented Nov 24, 2012 at 12:46
  • See Having a Multimap sorted on keys only in Java Commented Nov 24, 2012 at 12:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.