You use the same HashMap<String, String>
instance as value for all the keys of your TreeMap
, so of course all the keys will have the same value.
You should create a new HashMap
for each key:
....
while (itr.hasNext()) {
Entry e = (Entry) itr.next();
String key = (String) e.getKey();
name = ReadExcel.getString((String) e.getValue(), 0);
String email = ReadExcel.getString((String) e.getValue(), 1);
while (trans.hasNext()) {
HashMap<String, String> vessel = new HashMap<>();
Entry ex = (Entry) trans.next();
String NameVs = (String) ex.getKey();
String emailVs = ReadExcel.getString((String) ex.getValue(), 0);
if (name.equalsIgnoreCase(NameVs) && email.equalsIgnoreCase(emailVs)) {
vessel.put(NameVs, data.get(NameVs));
myData.put(key, vessel); //Putting data in treeMap
break;
}
}
trans = data.entrySet().iterator();
}
....