The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

How would I do my toString?
I want to be able to do something like this :
(main)

TestClass a1 = new TestClass[1,2,3,4];
TestClass a2 = new TestClass[5,6,7,8,9];
TestClass a3; // Need help on this also, how do I overload my constructor to get an empty set of array?
a3 = a1.concat(a2);
System.out.print(a3); //Want the results " 1,2,3,4,5,6,7,8,9,10 "

Now, that is how to override a toString() method. But what about printing out an array? Well, we can call a println on an array. Let's say we had a main which had an int array with the numbers 1 through 5. Then let's print out the array, both by just calling it, and with each int on its own line:

With all of that information (and your knowledge of looping through an array which I see you have), see if you can figure some of it out. If you have some trouble, feel free to ask.

Last edited by aussiemcgr; May 11th, 2012 at 02:29 PM.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/