Sort the array with the key
Arrays . sort ( newArr , ( a , b ) -> { if ( Integer . compare ( a [ 0 ] , b [ 0 ] ) == 0 ) return Integer . compare ( a [ 1 ] , b [ 1 ] ) ; return Integer . compare ( a [ 0 ] , b [ 0 ] ) ; } ) ;