Results 1 to 2 of 2
  1. #1
    Wolfie is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Post 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?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

Similar Threads

  1. Why isn't my toString method working
    By arri3oi in forum New To Java
    Replies: 7
    Last Post: 12-13-2010, 05:34 AM
  2. toString() method error?
    By blueduiker in forum New To Java
    Replies: 6
    Last Post: 02-07-2010, 03:19 AM
  3. Trying to write toString method
    By curious in forum New To Java
    Replies: 3
    Last Post: 10-28-2009, 02:43 AM
  4. toString() method
    By 01allenh in forum New To Java
    Replies: 2
    Last Post: 03-25-2009, 11:43 PM
  5. toString method
    By apfroggy0408 in forum New To Java
    Replies: 6
    Last Post: 01-31-2008, 04:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •