Casting string/object hashmap to string/number

Discussion in 'Plugin Development' started by Tster, Jan 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Tster

    Basically, I'm using this:
    getConfig.getValues, but a string / object hash map is returned.

    Is there a way, if I know that the values are all numbers, I can return it as a string / number?

    Also, when I say number, that is because I'm not sure which to use. I need decimal places, but haven't looked into floats, singles, doubles etc, so it can't be an integer.

    Ty
    Tster
     
  2. Offline

    GusGold

    Tster

    What do you mean "haven't looked into floats, singles, double"? As in you don't know what they are? If this is the case, you should probably get a grasp on what they are and what they do from here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html (Also, by single, do you mean a bit/boolean?)

    As for getting the right data types, take a look at what is called 'casting'. This is an unsafe method for telling java that the field is a certain type. Make sure to do checks before casting otherwise expect plenty of errors :)

    http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html Scroll down to the casting secion, although you will want to read all of it when you get the chance.
     
  3. Offline

    Tster

    I think i'll go with a double, I'll need a few dec places.

    Also, when I looked around about casting, I couldn't find out about casting an entire hashmap; at the moment I've been casting the values from objects to doubles when needed, but it doesn't feel like the easiest way :(
     
  4. Offline

    BillyGalbreath

    The String would be the key, and the Object would be your value (the Double).
     
  5. Offline

    Tster

    exactly, but whenever I want to use the value, I have to convert it from an object to a string and then to a double, I'm just wondering if there's an easier way
     
  6. Offline

    BillyGalbreath

  7. Offline

    Tster

    This is what I'm using at the moment (w/o the try catch, which I will amend in)

    Just wondering If i could cast the whole hashmap from string/object to string/double

    I'll stick with this, are there any other errors which might be thrown in doing this?

    Thanks alot mate
     
Thread Status:
Not open for further replies.

Share This Page