• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question Related to Maps  RSS feed

 
meera pillaiii
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Using java 1.5.

I want to convert this list into map structure.

My keys for map are maintaskid and subtaskid.

Map Structure is



Where first integer is maintaskid and second integer is subtaskid

How to convert the above list to map structure mentioned above.Any help is highly appreciated,
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You are being very specific about implementation details. Why do you want a tree map specifically?
You can create a Map from a Stream from your List:-If you are using a version of Java® older than Java8, you would have to use a loop to iterate your List. If your Map already contains the ID as a key (=using get() with that key does not return null), add the details to the List, otherwise put(...) a new List and add the details to that List. If you go through the Java™ Tutorials, your question is similar to the anagrams example at the bottom of that link.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Java5 was superseded nine years ago, why are you still using it?
 
meera pillaiii
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell Ritchie , My company is using java5 .

I already have code for one layer..



Now I want to convert the above to two layers like mainTaskId and subTaskId.

For example my map like

mapMain::{815={815=[com.bmtap.apse.database.hibernate.CsSectionDetail@4ed083fc], 912=[com.bmtap.apse.database.hibernate.CsSectionDetail@4ed083fc, com.bmtap.apse.database.hibernate.CsSectionDetail@4ed083fb, com.bmtap.apse.database.hibernate.CsSectionDetail@4ed08f56, com.bmtap.apse.database.hibernate.CsSectionDetail@4ed08f57]}}

Any help is highly appreciated...

 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That boolean parameter looks like bad design to me. That should be a different method.
you should not be putting a List into the Map. Only when get returns null should you put a new List. If you get a real List from get() you can simply add to that List.
The word is to not 2. If you are going to use text speak in your method titles you are going to confuse yourself, and you are going to get poor quality products.
What do you mean by two layers? Do you mean you have a map of maps? Are you going to organise some of your data one way and some another way? That sounds a good way to confuse yourself, and get poor quality products.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!