Results 1 to 2 of 2
- 03-06-2011, 11:02 PM #1Member
- Join Date
- Mar 2011
- Rep Power
using the toString method to print an array
Hi folks, I need some help on an assignment I am working on for class. Its due today. I am comfortable with most of what I have, I just can't get the method to return my array objects to string correctly. I am not sure what I am doing wrong.
I have an array:
C  r = new C[NUM_C];
and it works from the tests I have done on it. But, in this same class I need to create a method to print out the objects in the array by calling the toString method. I got it to work with the Arrays.toString but it formats the ouput funny. Like since the NUM_C is a constant, it attaches null values to the other elements in the array. The array is not suppose to be filled to capacity. Can anyone maybe lend a hand?
You may want to create a StringBuilder object and then iterate through the array and append to the StringBuilder if you want to create your own single String display of the array contents. If this doesn't help, then you may wish to provide a lot more detail on your problem, your desired solution and what's not working.
- By arri3oi in forum New To JavaReplies: 7Last Post: 12-13-2010, 06:34 AM
- By blueduiker in forum New To JavaReplies: 6Last Post: 02-07-2010, 04:19 AM
- By curious in forum New To JavaReplies: 3Last Post: 10-28-2009, 03:43 AM
- By 01allenh in forum New To JavaReplies: 2Last Post: 03-26-2009, 12:43 AM
- By apfroggy0408 in forum New To JavaReplies: 6Last Post: 01-31-2008, 05:08 AM