Whenever I try to print the char arrays to the console, I’m getting the result in integer format, but whenever I try to print integer arrays to the console, I’m getting the result in hashcode format. Could anyone please tell me why?
char[] arr={'4','5','6'};
System.out.println(arr); //456
int[] arr={4,5,6};
System.out.println(arr) //[I@3e25a5]
java.io.PrintStream(the class ofSystem.out) has a specialprint-method forchar[], but not forint[]. So for thechar[], this special method is used, whileint[]is printed via the generic version, which prints the hashcode (or, to be more precise, the result ofString.valueOf()called with the object as parameter).