The problem I'm having is that I have a min heap class that is created with java generics. In the class where I use the min heap class(call it sorter) I have a float array, which is full of primitive float values.

The constructor for the min-heap class takes a AnyType as a parameter. Now, creating a minHeap object(in the Sorter class) and trying to pass it a float array does not make java happy.

I'm trying to figure out how I can get my float values into the min-heap while still keeping java generics in the min-heap class.

The constructor for Min-Heap looks like this:

public Heap(AnyType [] f){

I have been calling the mean heap class in Sorter like this:

heap = new Heap(f); //f is a float[] f;

Any help would be appreciated. Looking around I've been seeing stuff about wrapping it in a Float object but don't know how to wrap the array.

8 Years
Discussion Span
Last Post by BestJewSinceJC

You can 'wrap' the array by creating a new Float[] array and then in a for loop, add each float primitive type to the Float array.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.