Reputation: 798
I have a LinkedHashMap based on "Double" data types.
LinkedHashMap<Double, Double> meetingRecord;
I want it to be in primitive data type
LinkedHashMap<double, double> meetingRecord;
As far as I know from different search, Java by default has no such data structure available and I need to use something from guava-libraries
or commons lang
Please help, what should be used, i am really stuck.
Upvotes: 1
Views: 110
Reputation: 6322
In your comment you state that you don't want to iterate through your values and convert from Double
to double
, but given the way that Java handles wrappers and primitives there really is no escaping that computation.
Whatever library you use to go from a collection of wrappers (objects) to an array of primitives, it will have to ask each wrapper object for the primitive value, essentially looping through the collection.
Having said that, Guava does this very nicely with:
double[] arrayOfDoubles = Doubles.toArray(meetingHistory.values());
Upvotes: 3
Reputation: 1948
You could use Commons Primitives (http://commons.apache.org/primitives/). However, you'd have to really, really care about performance to bother.
Upvotes: 0