S
Simone
Hello,
maybe my question has already been asked here but I couldn't find a
precise answer for now...
Is it possible to customize the way the implicit "toString" method,
invoked e.g. by System.out.print(...), will produce the output string?
If I write the following code:
int[] vector = new int[] {1,2,3,4};
System.out.println( vector );
the output is:
v = [I@1d9f953d
corresponding to an internal java information about the object (the
hash code, I believe).
With a "classic" object of a class, I can rewrite the toString()
method and output the string that I want, simply writing e.g.
System.out.println( objectName ). Is there a way to rewrite the
"implicit" toString() method for arrays, so that I can write
System.out.println( "v =" + vector ) and obtain the output: v =
(1,2,3,4) ?
Many thanks in advance.
Simone.
maybe my question has already been asked here but I couldn't find a
precise answer for now...
Is it possible to customize the way the implicit "toString" method,
invoked e.g. by System.out.print(...), will produce the output string?
If I write the following code:
int[] vector = new int[] {1,2,3,4};
System.out.println( vector );
the output is:
v = [I@1d9f953d
corresponding to an internal java information about the object (the
hash code, I believe).
With a "classic" object of a class, I can rewrite the toString()
method and output the string that I want, simply writing e.g.
System.out.println( objectName ). Is there a way to rewrite the
"implicit" toString() method for arrays, so that I can write
System.out.println( "v =" + vector ) and obtain the output: v =
(1,2,3,4) ?
Many thanks in advance.
Simone.