Is it possible in Java to override 'toString' for an Objects array?

Popokoko picture Popokoko · Apr 24, 2012 · Viewed 13.8k times · Source

Is it possible in Java to override a toString for an Objects array?

For example, let's say I created a simple class, User (it doesn't really matter which class is it since this is a general question). Is it possible that, once the client creates a User[] array and the client uses System.out.print(array), it won't print the array's address but instead a customized toString()?

PS: of course I can't just override toString() in my class since it's related to single instances.

Answer

Theodore Norvell picture Theodore Norvell · Apr 24, 2012

No. Of course you can create a static method User.toString( User[] ), but it won't be called implicitly.