Osman Khalid
Osman Khalid

Reputation: 798

equivalent data structure of LinkedHaspMap in guava or apache commons lang

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

Answers (2)

Francisco Paulo
Francisco Paulo

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

Neil
Neil

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

Related Questions