English 中文(简体)
如何在 java 创建散列表格
原标题:how to create a hash table in java

我有一个 2 列的 csv 文件 。 我正试图为每个维度创建一个散列表。 我正试图为每个维度创建一个散列表 - 只有当我之前没有看到过它时才添加一个值。 我想为每个列创建两个单独的散列表。 列包含字符串和数字值。 从分类定义我找到的包含 Key (Object 键) 介质测试, 如果指定的对象是此散列中的密钥 。 我可以解释像 Csv 文件看起来像下面一样的细节 。

New York, 50
Sydney, jessi
california, 10
New York, 10

因此,第1列,纽约在散列表2中出现2,我想把纽约和值2的钥匙放在纽约和值2上。

任何人都可以帮助我 怎样才能用这种方式 使用 Java 散列类来创建散列桌 或维持一个单独的阵列

问题回答

尝试 < a href=> "http://sourceforge.net/ projects/opencsv/" rel="nofollow" > 开放源码项目,名为 OpenCSV。

然后,你可以编解类似的东西 读CSV 在你的地图。

try {
    CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(new File("/path/to/your/file.csv"))));
    Map<String, String> result = new HashMap<String, String>();
    for(String[] row : reader.readAll()) {
        result.put(row[0], row[1]);
    }
} catch (FileNotFoundException e1) {
    e1.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

您可以在 OpenCSV 文档这里





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签