Is there a way to put an int and a Double in the same array. I want to have an array (p1[]) where the first (p1[0]) is an int and all the rest of the elements are doubles. Is this possible?
Is there a way to put an int and a Double in the same
Share
You can do this by having an array of objects that are superclasses of Integer/Double (as pointed out elsewhere).
However I would perhaps enforce type safety by implementing an object that has an
Integercomponent plus an array ofDoubles, and store an array of these. The upside (despite the additional complexity) is that you’ll have type safety and not have to cast the first element to anIntegerwhilst casting the remainder toDoubles.