I have two arrays, one stores the distance of the cities and the other stores the corresponding population. Everything works fine if the distance of the cities is in ascending o
public static void main(String[] args) {
Integer[] bidAmount = {3000, 54000, 2000, 1000, 5600};
String[] bidderName = {"Jenny", "Mike", "Alvin", "Berry", "John"};
Map stringTreeMap = new TreeMap<>();
stringTreeMap.put(bidAmount[0],bidderName[0]);
stringTreeMap.put(bidAmount[1],bidderName[1]);
stringTreeMap.put(bidAmount[2],bidderName[2]);
stringTreeMap.put(bidAmount[3],bidderName[3]);
stringTreeMap.put(bidAmount[4],bidderName[4]);
for(Map.Entry entry : stringTreeMap.entrySet()) {
Integer key = entry.getKey();
String value = entry.getValue();
System.out.println(key + " => " + value);
}
}