Przykład

public NullEmptyArray_Example() {
super();
}

public void addValue( Integer value ) {
if ( values == null ) {
values = new ArrayList(10);
}
values.add( value );
}

public Integer[] getValues() {
if ( values == null ) {
return null;
}
return (Integer[])values.toArray( new Integer[ 0 ] );
}

private List values;

public static void main( String[] args) {
NullEmptyArray_Example example = new NullEmptyArray_Example();
Integer[] values = example.getValues();
for ( int i = 0; i < values.length; i++ ) {
System.out.println( values[ i ] );
}
}

Rozwiązanie
Zamiast wartości NULL zwróć tablicę o zerowej długości.

public NullEmptyArray_Solution() {
super();
}

public void addValue( Integer value ) {
if ( values == null ) {
values = new ArrayList(10);
}
values.add( value );
}

public Integer[] getValues() {
return ( values == null ) ? new Integer[ 0 ] :
(Integer[])values.toArray( new Integer[ 0 ] );
}

private List values;

public static void main( String[] args) {
NullEmptyArray_Solution example = new NullEmptyArray_Solution();
Integer[] values = example.getValues();
for ( int i = 0; i < values.length; i++ ) {
System.out.println( values[ i ] );
}
}