• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Store several values in a one key in Java 1.4

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I usually program in Java 1.5 or higher, but now I need a HashMap, where the key is a String a and value - a list of values. Does Java 1.4 have something similar?
 
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java 1.4 HashMap
 
Marshal
Posts: 80056
409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot store multiple values on the same key in a Map. If you add the second value, it overwrites the first value.Remember you may have to cast the elements retrieved from a Collection or Map in Java1.4, otherwise they are all of type java.lang.Object.

If you want to store multiple values in a Map, you can’t; … but you can use a List as a value. The technique is the same in Java1.4 as it is in Java7, only Java1.4 didn’t support generics.

If you look at the documentation for HashMap, it will probably say “since 1.2”, so you can tell which versions of Java support it. Every class ought to have a since field.
 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create a custom class which suits your requirements of multiple list of values. Then you can use a MAP and add it in value part for the key. However since JDK 1.4 does not supports generic you may have to take care of runtime surprises
 
Eun Mi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Vinod Tiwari! I just have never programmed in 1.4. I'll try it !
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic