Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Java SortMap Descending :
public class SortMapDescending {
public static <K, V>
Map<K, V> sortByValue(Map<K, V> map)
{
final int size = map.size();
final List<Map.Entry<K, V>> meView =
new
ArrayList<Map.Entry<K,V>>(size);
meView.addAll(map.entrySet());
Collections.sort(meView, new
DescendingValueComparator());
Map<K,V> sortedMap = new HashMap();
for (int i = 0; i < size; i++) {
sortedMap.put(meView.get(i).getKey(),
map.get(meView.get(i).getKey()));
}
return sortedMap;
}
}
import
java.math.BigDecimal;
import java.util.Comparator;
import java.util.Map;
final class
DescendingValueComparator<V extends Comparable<?
super V>>
implements Comparator<Map.Entry<?, V>>
{
public int
compare(Map.Entry<?, V> o1, Map.Entry<?,
V> o2) {
return o2.getValue().compareTo(o1.getValue());
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.