How can I convert inInt [] to inShort []?
You need to create an array of shorts of the appropriate size and copy the contents. Although there are utility methods for copying arrays, I donβt know that it will copy an array of primitives and simultaneously convert values. Thus, you will most likely need to copy an element with an explicit for loop.
Do I need to allocate new memory for inShort [] ....
Yes. A new array is required ... if you do not have an existing array of the desired type and size, ready for reuse.
or is there a way I can use inInt []?
Not. You cannot convert an array-primitive type to another array-primitive type. The Java language will not allow this.
(And for the record, this applies to every array of primitives such as Java.)
source share