ArrayList to store the output
ArrayList < Integer > al = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < len - 1 ; i ++ ) { for ( int j = i + 1 ; j < len ; j ++ ) { if ( arr [ i ] == arr [ j ] ) {