This code
public static void main(String [] args){
int c[] ={10,21,34,36,90,33,44,5};
int tot = 0;
for(int i:c){
System.out.println(c);
}
}
Prints out
[I@1242719c
[I@1242719c
[I@1242719c
[I@1242719c
[I@1242719c
[I@1242719c
[I@1242719c
[I@1242719c
I know I'm supposed to print out the int variable, but I'm curious as to what this means. Thanks
You're printing out the internal representation of c
. Essentially [I@1242719c
breaks down to two important things. First, the [
indicates that you're printing an array. Second, the I
indicates that it's an integer. Therefore, you're printing an array of integers! Try replacing the integer array with a string array and watch the I
get replaced accordingly. From this page:
The name of an array's class has one open square bracket for each dimension plus a letter or string representing the array's type. For example, the class name for an array of ints is "[I". The class name for a three-dimensional array of bytes is "[[[B". The class name for a two-dimensional array of Objects is "[[Ljava.lang.Object". The full details of this naming convention for array classes is given in Chapter 6, "The Java Class File."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With