cast « double « Java Data Type Q&A

1. Double cast for Double smaller than zero

Double out = otherTypes.someMethod(c, c2);
assertEquals((Double)-1.0D, out);
I get error "Double cannot be resolved" (the Double in assertEquals), is there any way to hack around it except extracting variable? Is this bug in Java ...

2. Incorrect results for average distance using Dijkstra (java)

The graph is unweighed, an element of the array of HashSets neighbours[] is a node neighbours[1] is node 1 (they start from 0 mind you) with its unique neighbouring nodes say ...

3. Value change when converting a long to a double and back

given the following code:

long l = 1234567890123;
double d = (double) l;
is the following expression guaranteed to be true?
l == (long) d
I should think no, because as numbers get larger, the gaps ...

4. How to cast from List to double[] in Java?

I have a variable like that:

List<Double> frameList =  new ArrayList<Double>();

/* Double elements has added to framList */
How can I have a new variable has a type of double[] from that ...

5. cast numerics to double efficiently

I have a bunch of numeric values. They can be Short, Integer, Long, Float or Double (and are the output of an external library (snakeYaml) which returns these as type Object) I'd ...

6. Java correct way convert/cast object to Double

I try to found, but all seems vague. I need convert Object o to Double. Is correct way first convert to String? Thanks.

7. casting String into double

8. Type casting a string into a double

You are going to have to use a StringTokenizer object to seperate your input into tokens then setting each token into a string and using the Double.parseDouble("the double in string format"); then you would add it to the vector. StringTokenizer tokenizer = new StringTokenizer(line); String aWord; while((aWord= tokenizer.nextToken())!=null){ double myNumber = Double.parseDouble(aWord); vector.add(myNumber); }

10. casting an Object type to double