This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing arrayLists in groups on the JSP page  RSS feed

 
Ricky Jay
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to print out an arraylist in my JSP page with headings. Here is an example:

Data..
ID Model Make
1 S10 Chevy
2 F150 Ford
3 F250 Ford
4 Silverado Chevy
5 Tacoma Toyota
6 T100 Toyota
7 Ranger Ford

Chevy
1 s10
4 Silverado

Ford
2 F150
3 F250
7 Ranger

Toyota
6 T100
7 Tacoma


When doing it like this...


I'm getting

Chevy
1 S10
Ford
2 F150
Ford
3 F20
Chevy
4 Silverado
Toyota
5 Tacoma
Toyota
6 T100
Ford
7 Ranger

How do I go about sorting this data to be put under a heading of "Make". Is this not something that should be put into an arraylist?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the right collection type for your data is your best bet. Your data isn't just a simple list, so a List probably isn't the best implementation.

How would you better organize the data to reflect the abstraction that it represents?

I find it sometimes helps to sketch out the layout of the data to see how it can best be represented.
 
Ricky Jay
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still kinda new...the only collection I have worked with thus far has been arraylists.

Is this something I would need to takle with a map? Any suggested reading?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need some grounding in basic data structures. I'd hit the tutorials.

For this exercise, you have multiple lists, one for each make. So each list should be a List implementation. Each List is associated with something else -- a make. So a Map is good to capture the association.

So how would you use Maps and Lists to model your data?
 
Ricky Jay
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I will have to get back to you on how I would tie the two together. I'm going to have to read up on maps. Thanks for pointing me in the right direction...I'll post my conclusion later.
 
Ricky Jay
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After briefly reading about map topics(hashMap treeMap) I've noticed it uses a KEY,Value combination.

I haven't tested this yet, but I'm thinking about
Pseudo:
key=make
value=listObject
store it as a map...then just recall the list by the "make" key.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!