+ 13

How to print charArray() after a string literal?😭

Why the output is: Name = [C@c7ebf41 How to print charArray() after a string literal? Please help me😭 https://code.sololearn.com/cE9cfJTNLVcn/?ref=app

26th Jul 2017, 12:29 PM
Fuyuka Ayumi(冬花)
5 Respuestas
+ 16
class Program{ public static void main(String[] args) { String f = "Fuyuka"; char[] fuyu = f.toCharArray(); System.out.println("Name = "+(new String(fuyu))); } }
26th Jul 2017, 12:41 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 13
I believe you need to print the array contents using a loop. for(char c: fuyu){ System.out.print(c); } https://stackoverflow.com/questions/13505274/java-println-with-char-array-gives-gibberish According to the link, the 'gibberish' is the memory address of the object.
26th Jul 2017, 12:35 PM
Hatsy Rei
Hatsy Rei - avatar
+ 11
Yes. The problem occurs because you try to append fuyu with a string. You may look up "Object.toString()", which can be used in this case.
26th Jul 2017, 12:41 PM
Hatsy Rei
Hatsy Rei - avatar
+ 11
@Hatsy sir i have already tried fuyu.toString() it doesn't work. Thanks you @Valentin yes i knew it was just some basic thing. It works now thanks for the help😊😇
26th Jul 2017, 12:43 PM
Fuyuka Ayumi(冬花)
+ 10
@Hatsy sir, It works if directly print array only like this. System.out.println(fuyu); but when i includes string literal like: System.out.println("name =" + (fuyu)); it comes up with the address, Theres some very basic thing I'm missing here😥
26th Jul 2017, 12:39 PM
Fuyuka Ayumi(冬花)