int [ ] toIntArray ( ) { int [ ] out = new int [ size ( ) ] ; int a = 0 , b = out . length ; for ( int i = - 1 ; ( i = ints . nextSetBit ( i + 1 ) ) >= 0 ; ) { int n = decode ( i ) ; if ( n < 0 ) { out [ a ++ ] = n ; } else { out [ -- b ] = n ; } } //if it contains -3, -1, 0, 1, 2, 4 //then out will be -1, -3, 4, 2, 1, 0 reverse ( out , 0 , a ) ; reverse ( out , a , out . length ) ; return out ; }
Converts this set to a new integer array that is sorted in ascending order .