+ 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
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)));
}
}
+ 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.
+ 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.
+ 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😊😇
+ 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😥