0

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

User420
  • 137
  • 3
  • 12
  • 1
    Why is Live Tomcat Server trying to compile a Java program??? I have a feeling you've misidentified the problem. I think you need to focus on tracking down and fixing that, instead of doing damage to your Java code. – ajb Jul 28 '16 at 03:28
  • 1
    @ajb JSP probably? – xiaofeng.li Jul 28 '16 at 03:29
  • And I agree the production environment should not have to compile java code. – xiaofeng.li Jul 28 '16 at 03:29
  • 2
    What Java version is your Tomcat server running on? Pre-Java 5? – Robby Cornelissen Jul 28 '16 at 03:29
  • 3
    As @RobbyCornelissen is hinting, you should upgrade your Tomcat server to run on a newer version of Java. To get that error, you're running on Java 1.4 or earlier. Java 1.4 came out in 2002 and was end-of-lifed in 2008. *It's ancient!* – Andreas Jul 28 '16 at 03:45
  • 1
    pls post the part of your code where you get the error and version of your java and Tomcat too – Adliano Alves Jul 28 '16 at 04:04
  • Thanks for suggestions guys but I tried to advise the management to upgrade the Java, but i don't enough privilege to do it. So the best way for me is to stick with the current version, Java 1.6. – User420 Jul 28 '16 at 05:12

1 Answers1

0

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

athina
  • 94
  • 2
  • Im planning to map multiple values to a key but Maps. put(K key, V value) will overwrite the the previous value mapped to the key. Thanks for the suggestion – User420 Jul 29 '16 at 01:39
  • Then you could retrieve firstly the values and the add to them your new list and save again to the key for example: List rowvalues = (List ) rowmap.get(key); rowvalues.addAll(rowlst); rowmap.put(key, rowvalues); – athina Jul 29 '16 at 06:47