• 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

Need to know what kind of values and how to pass them to Map<String String>

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Device class under my DeviceCOntainer package that declares a map and then the setter and getter for it like so:



Then I have an App class also under the DeviceContainer package where I am trying to set the values for this Map. Like this:



I get no errors when I leave null between the ( ), but I am trying to add this to a web service and there has to be a value there. I have tried putting many diferent things between the ( ), such as ("property1", "property2"), (String "property"), (Map<"property1", "property2">) and many other variations, but I always get errors. So if I am wanting to just set this to a simple string or set of strings, what is the correct syntax to do so? I have never worked with the Map class, so I am readng up on it now, but I wanted to go ahead and post this now in case I am unable to figure it out on my own. That way hopefully there will be an answer here by the time I get through with the reading. Im guessing this is a pretty simple problem for most of the vets here.

Thanks
 
Sheriff
Posts: 22784
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
You need to create a Map<String,String> object, add all properties, and then use that object as your parameter.
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I would create this as its own class under the DeviceContainer package? Something like

class DeviceProperties{
String property1;
String property2;

}


Then in the App classs I would need to do:

DeviceProperties properties = new DeviceProperties;

device.setProperties(properties);


But that still leaves each property blank, so I suppose I would need setters in getters in the new DeviceProperties class right? Is this about right, or is there an easier way to go about it?


edit - Im guessing I would need to use put(Object key, Object value) which is something Ive been reading about while looking into the map class right?
 
Rob Spoor
Sheriff
Posts: 22784
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 was more thinking this:
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks man, your the greatest, exactly what I was needing. Works perfectly.

At least I was on the right track when I guessed I would need to use put () x-P
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You guys should get a donation link going, I know they do that at cybertechhelp.com, and I donate every year, because just like this site, I get tons of great help.

Thanks again for the great info
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here you can donate to the site.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Kohanek wrote:You guys should get a donation link going.

What makes you think we don't already have such a link?

And thank you for the kind remarks about us
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I looked around a bit for it but couldnt find one.

As soon as I get paid in a couple of weeks you are going to see my status changed to "gravedigger"

unless I change my mind about which one to choose between now and then x-)
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So um, how do I go about changing my status to something of my choosing? I made the donation but I havent been presented with the option to do so
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That last sort of question is usually discussed on the "Ranch Office" forum.
reply
    Bookmark Topic Watch Topic
  • New Topic