• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

How to do looping in collection ?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My SQL returns the values as like below.


I'm getting the result and iterate the values to display.But in the last column need to display the values as different format.



Display format is...



How to append prizes 4 rows values in first row ? How to loop through here ?
Please help me.


 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bob

Welcome to Java Ranch

If possible, change the DB table structure .. apply 1NF and 2NF to aggregate Prize columns into single row for any Student.
If it is not possible, then, you can define a Map with key as Student id (String type) and value as Set of Prizes [ Map<String,Set><String>].

While iterating through DB records,



now you have a map of Prizes with Student id as key. So at the end of iteration, you shall have a Set of Prize 1,2,3,4 for Student id 121.

~ abhay>
 
bob peter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.
How is this works ? Is this possible in 1.5 ? Is giving me an syntax error.
Map<String,Set><String> prizeMap = new HashMap<String, Set><String>();

Thanks
 
Marshal
Posts: 67255
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you are trying to accomplish, but the following is not valid syntax: Map<String,Set><String> prizeMap

Did you mean Map<String,Set<String>> prizeMap?
 
bob peter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But HashMap won't support dublicate values or key. ? if adding more than one dublicate values , its going to overwrite...I want all values as like and only different is last column adding all rows values into one column.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , I meant Map<String,Set<String>> prizeMap
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!