Simoyw
Simoyw

Reputation: 691

How to convert List<Map<String,Long> to TreeMap or Map?

How to convert a List< Map.Entry < String,Long > > to TreeMap < String,Long > ?

    TreeMap<String,Long> tm1=new TreeMap<String, Long>();     
    List<Map.Entry<String,Long>> first = new ArrayList<Map.Entry<String,Long>>(tm1.entrySet());

    //Convert list back to TreeMap
    ??

I can't use Java 8 because this program run in a Hadoop program in Amazon Web Services that support only Java 1.7.

Upvotes: 0

Views: 3797

Answers (1)

sol4me
sol4me

Reputation: 15718

Iterate over list and add to treemap. E.g.

    for (Map.Entry<String, Long> entry : first) {
        tm1.put(entry.getKey(), entry.getValue());
    }

Upvotes: 2

Related Questions