CODE IS NOT WORKING

package practise;

public class main1 {
public static int[] arr(int[] b,int data, int si,int count)
{
if(si==b.length)
{
int[] bb=new int[count];
return bb;
}
int[] index=null;
if(b[si]==data)
{
index=arr(b,data,si+1,count++);
}
else
{

	index=arr(b,data,si+1,count);
} 
if(b[si]==data)
{
	index[count]=si;
}
return index;

}
public static void main(String[] args) {
int[] result = {1,8,8,2,5,4,8,5};
int[] check=arr(result,8,0,0);
for(int i : check)
{
System.out.print(i+" ");
}

}

}

index[count]=si;
do count -1 here. because size of array is count and it will go out of bounds otherwise.

can pls explain i am getting it

can you pls explain mam i am not getting it what you are trying to say

your array has positions from 0 to count-1,so do
index[count-1]=si;