I have this simple code in which an arraylist will be passed to a hash map to remove the duplicate records and add all the records back to the same araylist:
ArrayList<String> masterRecords = new ArrayList<String>();
String perLine;
// Read file per line
while ((perLine = br.readLine()) != null) {
masterRecords.add(perLine);
}
br.close();
// Remove duplicates using hash map
HashSet<String> uniqueRecords = new HashSet<String>();
uniqueRecords.addAll(masterRecords);
masterRecords.clear();
masterRecords.addAll(uniqueRecords);
My data is a csv record, something like:
/EON_2,-,EON_2,9R25M_ROADM_001,OCH-L-1-1-1-68,OPT-F,PMTypeOptical,NEND,TDTC,15-MIN,Dec 08 2014 - 10:30:00 PM MYT,NA,NA
The problem is all records are not in the same order and I want to preserve how they were sorted before, I read that using linked hash map can do the same (remove uplicates) and at the same time preserve the order of the records. I can't seem to find a good example on how to do it. Anyone can point me to one or have a basic example on how to do it? thank you