public static long [ ] insertEntry ( long [ ] a , int idx , long val ) { long [ ] b = new long [ a . length + 1 ] ; for ( int i = 0 ; i < b . length ; i ++ ) { if ( i < idx ) { b [ i ] = a [ i ] ; } else if ( i == idx ) { b [ idx ] = val ; } else { b [ i ] = a [ i - 1 ] ; } } return b ; }
Gets a copy of the array with an entry inserted .