如何使用数据结构对HashMap键进行排序,然后将键及其相关值打印出来?

问题描述

首先让我说我不想使用TreeMap或任何内置的排序类。

我目前在CSV文件中有一长串产品代码及其相关名称。我创建了一个解析器,用于存储CSV文件中的一些值:

  1. 将产品代码存储到名为productCodesList的ArrayList中。
  2. 将产品名称存储到名为productNamesList的ArrayList中。
  3. 一个名为productMapper的HashMap将产品代码映射到它们各自的产品名称

我的目标是使用一些我将要实现的算法对productCodesList进行排序。我已经实现了ArrayList快速排序,该排序成功地以升序返回键。现在,对于如何使用这些现在排序的键以并排显示其关联值的方式引用HashMap感到有些困惑。关于如何前进的任何提示

我正在做的事的一个例子---------

Key: "3" Value: "Oranges"
Key: "1" Value: "Bananas"
Key: "7" Value: "Peaches"
Key: "15" Value: "Tomatoes"

***After the key values are sorted using quicksort,print properly sorted HashMap keys with their values***

Key: "1" Value: "Bananas"
Key: "3" Value: "Oranges"
Key: "7" Value: "Peaches"
Key: "15" Value: "Tomatoes"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)