Sorting Parallel Arrays in Java

后端 未结 5 627
青春惊慌失措
青春惊慌失措 2021-01-21 06:19

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

5条回答
  •  猫巷女王i
    2021-01-21 06:54

       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);
        }
    
    
    }
    

提交回复
热议问题