• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Group a table by column and save them to separate lists

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what my table in the database looks like.

NumValue
110
120
230
215
325
335


I'm fetching them from the database and I want to save value corresponding to 1, 2 and 3 in separate lists. I know (maybe!) Map<Key, List<Integer>> is what I need but I don't know how to do it.
Output expected is:



Code is appreciated. Thanks in advance.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In pseudo (we don't hand out ready made code here at the ranch)

Query for all data from DB
Iterate over each record
Lookup map if entry for  key (num) exists
If yes, retrieve value (list) and add db value to list
If no, create key+value entry with existing values.
Repeat
 
reply
    Bookmark Topic Watch Topic
  • New Topic