• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Method to add values to hashmap

 
Ranch Hand
Posts: 226
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that has methods which adds primitives and objects to hashmaps. Would it be a good idea to create one method that can take multiple parameters of various data types and add them to a hashmap? I have code in many methods that places things into different hashmaps. I was thinking of having a single method that would place things into a hashmap whenever my methods need to place things in a hashmap.
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have an application that has methods which adds primitives and objects to hashmaps


You can't add primitives to the hashmap directly. First they should be convert to Wrapper type using autoboxing then it will get added.

Would it be a good idea to create one method that can take multiple parameters of various data types and add them to a hashmap?


It is not good to add several types of data in single hashmap. That's why to avoid this we use Generics which provides compile time error instead runtime.

.

I was thinking of having a single method that would place things into a hashmap whenever my methods need to place things in a hashmap.


How do you differentiate which map should be used to add any particular value..
 
Author
Posts: 213
10
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's usual to create code in response to a need, not just because. That need might be a functional requirement or it might be a design goal such as avoiding duplication. What's the problem you're trying to solve? What design goal would it serve?
 
I think I'll just lie down here for a second. And ponder this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic