I'm having a problem that I just can't see through at the moment. Been searching Google for an example but just not getting anywhere. Here's a (hopefully relevant & complete) snippet of code that I'm using: java.util.TreeMap inputParms = new java.util.TreeMap(); Double myDouble = new Double(someString); inputParms.put(new Integer(1), myString); inputParms.put(new Integer(2), myDouble); Basically, the TreeMap is to hold a set of parameters that are used elsewhere (they are the inputs used to call a stored procedure - that part is written by someone else, I just populate the TreeMap with the appropriate types and values). My problem is this throws an exception: java.lang.Double. If I use anything other than a Double object then I don't have a problem (I've tried String, Long and java.sql.Date, though not Float - just occurred to me now that I'd missed that). I tried using myDouble.doubleValue() and this throws an undefined symbol for the method put(int, double). I'm certain that someString can be converted to a Double without problems - have verified this several times. If I do Long myLong = new Long(someString), I don't have a problem. However Long isn't sufficient for my requirements. If somebody could show me a working example of putting a Double/double into a TreeMap or pointing to me a solid example I would appreciate it.
I tried using myDouble.doubleValue() and this throws an undefined symbol for the method put(int, double). I'm certain that someString can be converted to a Double without problems You can only put objects in a TreeMap. myDouble.doubleValue() is a primitive double, not an object. This isn't to do with converting a String to a Double. In Java 1.5, with autoboxing, you will be able to code map.put(int, double), and the compiler will box up (using the Integer and Double wrapper classes) the primitives automatically for you.