0
 ArrayList<Map.Entry<Integer, Float>> list = new ArrayList<Map.Entry<Integer, Float>>(datamap.entrySet());
        Collections.sort(list,new floatSort());

list is Map.Entry but contains only float point number. Now I want to compare the the list to other ArrayList type in Float. How can I cast from Map.Entry to float

John
  • 827
  • 5
  • 15
  • 25
  • Consider getting the values from the map: map.getValues() – Bohemian Dec 14 '12 at 19:50
  • Im trying to print the Map by the order of the sorted list. So I have to loop the map, find the value and then print the key. – John Dec 14 '12 at 19:52
  • Actually I'm using TreeMap. – John Dec 14 '12 at 19:54
  • John, if I understand your question right, you are trying to print your TreeMap sorted by values? If so, [this question + answer](http://stackoverflow.com/questions/2864840/treemap-sort-by-value) will help you out. @RichardJPLeGuen Thank you for showing me that meta link, I'll keep it in mind. – jlordo Dec 14 '12 at 20:01
  • Are you using `Map.Entry` objects because you actually need the entry keys, or because you didn't know how to extract your values from their HashMap? – Perception Dec 14 '12 at 20:19

2 Answers2

1

You can use Map.Entry.getValue.toString and then use Integer.parseInt to convert the string to int

String value = mapentry.getValue.toString;
int intValue = Integer.parseInt(value);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
0

to get your float value from the entry you need to get the value in your comparator.

Map.Entry <Integer, Float> entry = ...
float f = entry.getValue ();
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130