Woot4Moo
Woot4Moo

Reputation: 24316

Space efficient conversion from Wrapper to primitive and primitive to Wrapper

Given the following function:

public void convertToWrapper(long[] longsToConvert)  
{    

}  

and

public void convertToPrimitive(Long[] longsToConvert)  
{  
}  

Apache ArrayUtils exposes the following:

public Long[] toObject(long[] longs){
    final Long [] result = new Long [array.length];
        for (int i = 0; i < array.length; i++) {
             result[i] = new Long (array[i]);
         }
}

My question is there a way to do this utilizing only one array? I have tried the following which does not work:

for(int i =0;i<array.length;i++)  
{  
     array[i] = new Long(array[i]);
}  

Upvotes: 0

Views: 73

Answers (1)

David Grant
David Grant

Reputation: 14225

No. A Long[] is not the same type as a long[], so assignment will fail.

Upvotes: 5

Related Questions