I have written the below code to find out the key(String) that has the maximum value(Integer) using TreeMap in JAVA.
public static void maxprofitItem(int[] costs
You seem to be asking if using TreeMap instead of HashMap will give you a simpler way to find the key corresponding to the largest value/
TreeMap
HashMap
The answer to that is ... unfortunately ... No.