I have an array called list that contains string id, and double temp //names and values for weather stations
I want to sort the list by the value temperature.
public void Display2()
{
Arrays.sort(List);-System.out.println("Highest Temperature: " + List[0].GetID() + List[0].GetTemp());HOW DO I SORT BY TEMP?? GetID is the getter method for string id, and GetTemp is the getter method for GetTemp. Temp and ID were initialized on another .java file --WeahterStationData.java if that helps
System.out.println("Lowest Temperature: " + List[CurrSize].GetID() + List[CurrSize].GetTemp());
}
Exception in thread "main" java.lang.ClassCastException: WeatherStationData cannot be cast to java.lang.Comparable
at java.util.Arrays.mergeSort(Unknown Source)
at java.util.Arrays.mergeSort(Unknown Source)
at java.util.Arrays.mergeSort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at WeatherStationList.Display2(WeatherStationList.jav a:58)
at WeatherStationUI.RunIT(WeatherStationUI.java:36)
at WeatherStationUI.<init>(WeatherStationUI.java:18)
at Main.main(Main.java:11)