Why code is returning garbage value?

package CodingBlocks;

public class AllIndices {
public static void main(String[] args) {

	int[] arr = {3,8,1,8,8};
	int[] ans =allIndices(arr, 0 , 8 , 0);
	System.out.println(ans);
	
}


public static int[] allIndices(int[] arr, int si, int item,int count) 

{
	int[] indices=null;

	if(si==arr.length) 
	{
		int[] base = new int[count];
		return base;

	}
	if (arr[si]==item) {
		
		indices = allIndices(arr,si+1,item,count+1);
		
	}
	else 
	{
		indices = allIndices(arr,si+1,item,count);
		
	}
	if (arr[si]==item)
	{
		indices[count]=si;
	}
	return indices;
	
}

}

hi @pranavchoudharyy
what garbage value are you getting

Garbage value is [I@214c265e

@pranavchoudharyy
thats is not the garbage value it is the address of the array.
System.out.println(ans); here you are printing the address of ans array.
you have to print element inside the array using loop.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.