Java Reference
In-Depth Information
System.out.println(numbers);
// Invokes println(Object)
}
}
To summarize,
char
arrays are not strings.
To convert a
char
array to a string, invoke
String.valueOf(char[])
.
Some library methods do provide stringlike support for
char
arrays,
typically having one overloading for
Object
and another for
char[]
; only the latter has the desired
behavior.
The lesson for language designers is that the
char[]
type should probably have overridden
toString
to return the characters contained in the array. More generally, the array types should
probably have overridden
toString
to return a string representation of the contents of the array.
< Day Day Up >
Search WWH ::
Custom Search