1

It is a really simple question but I need an another eye to look at my code:

String strtr = "iNo:";
char[] queryNo = strtr.toCharArray();
System.out.println(queryNo + " =this is no");

and the output is:

[C@177b4d3 =this is no

What are these characters, do you have any idea?

Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
hassasin
  • 141
  • 1
  • 1
  • 7

4 Answers4

7

That's how toString() is implemented for arrays.

The [C denotes that is a char array, 177b4d3 is its hashcode.

You may want to look at

System.out.println(Arrays.toString(queryNo) + " =this is no");

if you want to see your original String again, you need this:

System.out.println((new String(queryNo)) + " =this is no");
jlordo
  • 37,490
  • 6
  • 58
  • 83
  • so are you saying it is normal? Shouldnt I see "iNo =this is no" I need to see the sting that I declare at the beggining – hassasin Nov 30 '12 at 08:32
  • 1
    @hassasin.. Then why not just print the string. You are aware that `string` and a `char array` are two different things right? – Rohit Jain Nov 30 '12 at 08:33
  • really thanks. I got these: [i, N, o, :] =this is no iNo: =this is the original no So I have the char array correctly, but when I want to print this char array I should use tostring or new String, right? – hassasin Nov 30 '12 at 08:40
  • `toString()` would give you what you had, `new String()` what you want. – jlordo Nov 30 '12 at 08:45
1

Arrays do not override toString(), it is inherited from Object.toString as

public String toString() {
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1

you are printing the object

queryno, as queryno is a character array of on dimension and java is an object oriented language which holds every thing in the form of classes it gives the class name [C to your array where [ denotes total dimension and C denotes character type of array, Rest is the hashcode of the object.

Jayant Varshney
  • 1,765
  • 1
  • 25
  • 42
0

You are trying to print the array and that is the reason you get gibberish. Try using Arrays.toString(queryNo) and you will see what you expected.

Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120