JAVA alternative to declare TreeMap

238 Views Asked by At

I'm trying to create a TreeMap which is capable of storing multiple beans(Row) mapped to one key. My current declaration of the TreeMap is :

Map<String, List<Row>> rowmap = new TreeMap<String, List<Row>>();

With this kind of declaration i can easily use this method to add :

rowmap.get(combinedKey).add(rowlst);

This was working well in my local machine. The problem due to some issue in the Live Tomcat server, I couldn't use the declaration mentioned above to declare the Map, it throws these errors :

Syntax error on token "<", ( expected
Syntax error, insert ")" to complete Expression
Syntax error on token "<", ( expected
Syntax error on token "(", invalid Expression

So I declared this way :

Map rowmap = new TreeMap();

this solves the previous error but i couldn't use rowmap.get(combinedKey).add(rowlst); to add multiple values to a key because .add is defined in List not TreeMap, from my understanding i need declare the TreeMap this way : Map<String, List<Row>> rowmap = new TreeMap<String, List<Row>>(); to be able to use rowmap.get(combinedKey).add(rowlst);.

It would be great if anyone could suggest a workaround to solve this problem. I'm open to all suggestion.Thanks a lot!

EDIT : Tomcat version : 5.5.9 Java version : 1.6.0_41-b02

1

There are 1 best solutions below

2
athina On

Instead of add method use put for Maps. put(K key, V value) for example: rowmap.put(combinedKey,rowlst);