I’m trying to override the toString method in Java to output from two arrays (of strings) into a string which I can then format with line breaks, which I assume use /n. I’m just getting to grips with Java and after looking at the documentation I’m still baffled as to how the syntax for something like this should look. If someone has an example they could show me or can explain a good method of doing this I would be most grateful.
Share
If you have a class with two arrays, and want to override the
toStringmethod to show these you do:Here is a complete example:
Output:
Here is a version with new-lines:
Output: