I have a program that creates lists and needs any assigned values to be 0. Its been running fine when I do with int[] humpty_dumpty = new int[20]; but to optimize the size of the lists I set them to Short[] and now my program is breaking because it takes the zero’s as inputs(and Short[] humpty_dumpty = new Short[20]; is making the default value null).
Is there a way to set it to default zero without having to iterate through the entire list(I can do this via a for loop but was wondering if there was a way to make its behavior similar to int)?
There is a difference between a
Short[]and ashort[]. Elements of the latter will be initialized to0becauseshortis a “primitive” type and cannot be null. The capitalizedShortclass will be initialized tonullbecause it is really just anObjectwrapping ashortvalue.