且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从txt文件读取特定值并将其放入HashMap中?

更新时间:2023-11-15 16:57:28

You could try this to populate the maps:

while(scan.hasNextLine())
{
    String key = (String) scan.next();
    Map1.put(key, scan.nextInt());
    Map2.put(key, scan.nextInt());
}

To access a single key, use hashmap.get(key).

To access the key or entry set as a whole, check out hashmap.entrySet() and keySet() methods

相关阅读

推荐文章