Skip to content
Advertisement

Why VSCode shows strange “@number” (like int[10]@9) for arrays when debugging?

This was a simple binary search code and while I was debugging it for my better understanding, I got this remark a = int[10]@9 in the debugging panel – what does it mean (especially “@9” part after the type)? int[10]@9 remark while debugging

/**
 * BinarySearch
 */
public class BinarySearch {

    public static void main(String[] args) {
        int a[]={1,3,5,14,22,37,54,77,99,110},target=99 ;
        System.out.println(binarysearch(a,target)); 
    }
    static int binarysearch(int a[], int target)
    {
        int s=0,e=a.length-1;
        int mid;
        while(s<=e)
        {
            mid=s+e/2; //mid= 4 
            if(target<a[mid]) //false
            e=mid-1;//
            else if(target > a[mid])//true
            s=mid+1;
            else if(a[mid]==target) {
            return mid;
            }

        }
        return -1;
    }
}

Advertisement

Answer

By default, the debugger shows the toString() value of an object. As arrays don’t override the toString() method, it just uses the default implementation inherited from Object.

As the documentation says here, the string is constructed in the following way:

getClass().getName() + '@' + Integer.toHexString(hashCode())

So, that’s exactly what you’re seeing: the class name, the ‘@’ symbol, and the hash code.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement