| Author |
Nested Loop
|
John Seals
Greenhorn
Joined: Dec 30, 2008
Posts: 5
|
|
Greetings:
I am building a "tree view" and I need to be able to display the information in a specific way. Let's say my data looks like this:
(imagine this as a two column database)
a 1
a 2
a 3
b 4
b 5
b 6
But i need to display it like this:
a: 1
2
3
b: 4
5
6
What is the best way to do this? I don't think that this is too easy in SQL so I am trying to figure out how to do a loop in my servlet to build this. Do I write a loop with a conditional of some kind?
I am thinking this has a simple solution but I am not seeing it.
Muchas gracias!
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
Use java.util.Map<String,List<String>> (you can use one of it's implementations, java.util.HashMap perhaps) to store data. I assume you know how to get the data from database?
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Mohamed Khamis
Greenhorn
Joined: Oct 18, 2009
Posts: 3
|
|
You can store the first column in a string, for example
|
 |
John Seals
Greenhorn
Joined: Dec 30, 2008
Posts: 5
|
|
|
These are both great tips! Thanks for the quick replies gentlemen.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
Welcome to JavaRanch, Mohamed Khamis
|
 |
Mohamed Khamis
Greenhorn
Joined: Oct 18, 2009
Posts: 3
|
|
Campbell Ritchie wrote:Welcome to JavaRanch, Mohamed Khamis 
Thanks glad to be here.
|
 |
 |
|
|
subject: Nested Loop
|
|
|