I need a TreeMap in which Key will be id and value (will be a hasMap in that name will be id & values will be rest details) for every id data?

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 
        trans = data.entrySet().iterator();

Browse More Popular Posts

Leave a Comment