skip to Main Content

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;
    }
}

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Some debuggers annotate objects with an additional unique number reflecting the "identity" of the object, so you can easily tell if two different references are referencing the same object, versus two objects with the same values. This is not always the "identity hash code" referred to in the other answer, but can e.g. refer to "this was the Nth object allocated" in a test scenario.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search