我面臨的問題是讀取某個number
不是唯一的,而date
也不是這個數字唯一的。用於兩個非唯一值的數據結構
該程序是非常計算密集型,在我的ide上表現不是很好,因此我面臨使用正確數據結構的問題。
目前,我已經創建了一個index
和我讀number
到一個HashMap中和date
到其他HashMap
。然後,如果我需要他們,我只是匹配他們。然而,讀入每個都有一個while循環。
public HashMap<String,String> getEventDates() throws Exception {
String csvFile = "C:\\Users\\test.csv";
CSVReader reader = new CSVReader(new FileReader(csvFile), ';');
String [] line;
HashMap<String, String> eventMap = new HashMap<String, String>();
while ((line = reader.readNext()) != null) {
eventMap.put(line[15], line[13]);
}
reader.close();
return eventMap;
}
public HashMap<String,String> getNumberToEventDates() throws Exception {
String csvFile = "C:\\Users\\test.csv";
CSVReader reader = new CSVReader(new FileReader(csvFile), ';');
String [] line;
HashMap<String, String> isinMap = new HashMap<String, String>();
while ((line = reader.readNext()) != null) {
isinMap.put(line[15], line[4]);
}
reader.close();
return isinMap;
}
應該使用哪種數據結構來提高性能?我怎樣才能合併這兩種方法?
我很感謝你的回答!
UPDATE
哦,我很抱歉。
事實上,在每次迭代line[15]
之後,這只是我創建的索引。
如何合併這兩個功能?
所以,從我的理解你的標題說了兩個獨特的價值觀,但你的文章說他們不是? –
也許你可以用日期和數字創建事件對象並創建一個String,Object hashmap? – kai
爲什麼不使用相同的循環並返回List>與兩個HashMaps內? –
Chexpir