Strange toCharArray() behavior

前端 未结 4 1161
长情又很酷
长情又很酷 2021-01-20 03:29

I was experimenting with toCharArray() and found some strange behavior.

Suppose private static final char[] HEX_CHARS = \"0123456789abcdef\".toCha

4条回答
  •  日久生厌
    2021-01-20 04:14

    Arrays are objects, and its toString methods returns

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

    In your case [C@19821f means char[] and @19821f is its hashcode in hex notation.

    If you want to print values from that array use iteration or Arrays.toString method.

    `System.out.println(Arrays.toString(HEX_CHARS));`
    

提交回复
热议问题