I have a requirement where I need to read tabbed separated data from a file and put it in map with particular keys. Right now, what I am doing to split the data, create the String[] and put it into hashmap. Sample code on how I am doing it is provided below:
while ((line = bufferedReader.readLine()) != null) {
String[] data = line.split("\t");
myHashMap = new HashMap<String, String>();
for (int i = 0; i < data.length; i++) {
myHashMap.put("<key>"+i,data[i]);
}
<additional logic>
}
The problem is I have to read almost 2500 files each having around 1000 lines. This result into high memory usage and performance issue. As far as I know String are always costlier with regards to memory. So I am looking for it better approach to tackle this requirement.
Thanks for your help.