why we call allindices in if block i.e. when arr[si]==data;
i can’t get through it please explain
is their another way to do that?

We intend to reach the end of indices through recursion to know the length of the output array.
FOr this we keep passing in the count variable in recursive call.
Post the recursive call we know the position where the result is matched and set this position in the method.