Forums Register Login

@Override toString(double[] a)

+Pie Number of slices to send: Send
Dear Mooses,
I'm trying to override toString(double[] a) method, to get my own way of printing Arrays.toString(arrayName). Is it like:

and then I recall it like:

but the result is just like original toString without any own modification.
What am I doing wrong?

cheers
1
+Pie Number of slices to send: Send
You probably imported the java.util.Arrays class and called its toString(double[]) method, which can not be overridden. toString(double[]) is a static method of the Arrays class. Static methods can't be overridden (only hidden). Arrays also doesn't have an accessible constructor, so you can't extend it.

You should name your class something different than Arrays, and you should make the methods static. If it's a utility class, give it a private constructor without parameters and an empty implementation.
+Pie Number of slices to send: Send
Ok, thanks a lot.
+Pie Number of slices to send: Send
overriting just simply toString() without any parameter inserted gives the desired effect.

and


returns what I want ([5.403208456693433* , 4.094773757770066* ,.. and so on).

+Pie Number of slices to send: Send
Glad you figured it out
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 486 times.
Similar Threads
Arrays.asList(myArray).indexOf(value) return -1
Removing one array of strings from another
Simplifying this code
for this below java program why output is shown like this?
Array sorting(evens and odds)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:49:14.