HI All
i am new to java
jdk 1.4 and tomcat 4
my requirement is 
id   desc  name firstname lastname
1   hi         ravi     m               last
1   hi         ravi     m               middle
1   hi         ravi     m               mapp
2   hi         kiran     ha               hey
3   hi         vinoth     hello              yes

id is ----id 
 desc  name firstname lastname  --values 
 i am using treemap i want o/p like (map will not allow duplicate keys but i want the below o/p using map)
 id   desc  name firstname lastname
1   hi         ravi     m               last, middle,mapp
2   hi         kiran     ha               hey
3   hi         vinoth     hello              yes

please help me to solve 

What are the keys you want to use to access the data?

Why do you want to use a Map to store the data?

jdk 1.4 and tomcat 4

Firstly, install components that are not 10 years old. There is no reason to be using 1.4 and Tomcat 4.

Regarding your question, you could build your map by checking for the key before you put the value and if it exists, concatenate the new value to the existing and put that in the map.

Edited 4 Years Ago by Ezzaral

Java 1.4 was replaced in Sept 2004. Java 5 includes mnay language enhancements, particularly to Maps and Collections. We are now on Java 7. You computer is also critically at risk because you are missing many years of security patches and fixes.

To store multiple values for one key, use a collection (eg ArrayList) as the value, and store the multiple values in the collection. Eg with name as key and Person objects as values, replace Map<String, Person> with Map<String, ArrayList<Person>>. (You need Java 1.5 or later to support that syntax). Then to add a Person, check if the key does not exist and create a new key & ArrayList if necessary. Then add the Person to the ArrayList. Use the enhanced for-each loop (Java 1.5 or later) to loop thorugh all the Person objects for a single key

This article has been dead for over six months. Start a new discussion instead.