Results 1 to 7 of 7
  1. #1
    kira137 is offline Member
    Join Date
    Oct 2009
    Posts
    14
    Rep Power
    0

    Default I have a problem filling out this method

    /**
    * Initialize a new list by copying values from the given list.
    */
    public IntList(IntList copyFrom) {

    // FIXME
    }

    this is what was given to me..
    Is this suppose to make array from 'copyFrom' into new array?
    I'm not sure what value is given to me from IntList copyFrom..

    The array that I have is called values.
    and this method is inside the class called IntList

    thank you in advance

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You need to copy all values from the passed in IntList object (called copyFrom) to this currently executing IntList object.
    P.S That is more commonly called a constructor rather than a method.

  3. #3
    kira137 is offline Member
    Join Date
    Oct 2009
    Posts
    14
    Rep Power
    0

    Default

    ohh I see, but then i tried

    values = copyFrom;

    and it gave me 'incompatible types' error..
    what did I do wrong?

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

    Default

    Loop through the list perhaps or use one of the methods of List (if this is a java.util.List) to help you copy.

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Of course it did. What is the type of values? Obvoiusly not IntList because copyFrom is of type IntList. You need to copy every thing inside copyFrom to this object.

  6. #6
    kira137 is offline Member
    Join Date
    Oct 2009
    Posts
    14
    Rep Power
    0

    Default

    values type is int.
    would this work? I compiled it and it did go thorugh.. but I'm not sure it would copy the array from IntList copyFrom to my current IntList

    Java Code:
    count = copyFrom.size();
       values = new int[count];
       for(int i = 0; i < count; i++){
         values[i] = copyFrom.get(i);
       }

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

Similar Threads

  1. Method problem
    By Jeff6461 in forum New To Java
    Replies: 1
    Last Post: 03-02-2009, 06:48 AM
  2. Filling 2D Array
    By Nakira in forum New To Java
    Replies: 3
    Last Post: 11-12-2008, 12:43 PM
  3. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  4. Replies: 4
    Last Post: 09-13-2008, 11:07 AM
  5. Problem with sort method
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 07:12 PM

Posting Permissions

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