• 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

Collection with 3 keys

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am looking for a collection where I could save 3 keys and data.
Key1_1, Key2_1, Key3_1, data1_1, data2_1, data3_1
Key1_2, Key2_2, Key3_2, data1_2, data2_2, data3_2
Key1_3, Key2_3, Key3_3, data1_3, data2_3, data3_3
Key1_4, Key2_4, Key3_4, data1_4, data2_4, data3_4

Which collection would suit for it or maybe have I take apache commons collection?

Thank you in advance.

Best regards,
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you can write a simple wrapper around the core HashMap class -- one that uses a class that hold three objects, and calculates a new hashmap and equals based on it. This way, you can use the standard hashmap class.

Henry
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use Apache Commons Collections. They have already implemented this.
 
mic ta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which Apache Commons Collections could I use or where could I find a similar example?
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MultiKeyMap
 
mic ta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a code in order to read following input file:




But unfortunately I could not find how to save the information to MultiKeyMap.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Step 1: create a MultiKeyMap before the loop.
Step 2: inside the loop, call one of the put methods on the MultiKeyMap you created in step 1.
Step 3: oh wait, there isn't.
 
mic ta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


line[0], line[1] and line[2] are my keys, but how can I save line[3] and line[4] as values?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MultiKeyMap doesn't support multiple values. That leaves you with a few options:
1) use two separate MultiKeyMaps, with the same keys. The first stores one value, the second the other.
2) store your two values in a container like a String[] or List<String>
3) create a new class for containing the two values.
4) ???
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What's wrong with my original suggestion of writing a simple wrapper around the core hashmap?

Henry
 
mic ta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Henry: I try to use available frameworks in order to increase the readable of the code.

How can I print the content (keys and values) of col on screen?

 
mic ta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would looks a simple wrapper around the core hashmap?
 
mic ta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I rewrote the code with help of HashMap, but unfortunately the output is wrong (the input data is in first post):


I do not know how to fix the first keys column in output.



What did I wrong?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic