jeudi 2 avril 2015

Java println(charArray + String) vs println(charArray)

I have



char c1 = 'S'; // S as a character
char c2 = '\u0068'; // h in Unicode
char c3 = 0x0065; // e in hexadecimal
char c4 = 0154; // l in octal
char c5 = (char) 131170; // b, casted (131170-131072=121)
char c6 = (char) 131193; // y, casted (131193-131072=121)
char c7 = '\''; // ' apostrophe special character
char c8 = 's'; // s as a character
char[] autoDesignerArray = {c1, c2, c3, c4, c5, c6, c7, c8};


And



System.out.println(autoDesignerArray + "Mustang");


Output: [C@c17164Mustang



System.out.println(autoDesignerArray);


Output: Shelby's


I'm not understanding why I get the weird output when I concatenate the char array with a string. What is the "[C@c17164"? The location in memory? And why do I get that when I concatenate with a string, but I get what I would expect when I print it alone?


Aucun commentaire:

Enregistrer un commentaire