To check the length of remaining array after last zeroindex
if ( N - ( int ) zeroindex . get ( zeroindex . size ( ) - 1 ) - 1 > maxlen ) { maxlen = N - ( int ) zeroindex . get ( zeroindex . size ( ) - 1 ) - 1 ; } } System . out . println ( maxlen ) ; }