Results 1 to 6 of 6

Thread: Storing objects

  1. #1
    paul1024's Avatar
    paul1024 is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default Storing objects

    ..........
    Last edited by paul1024; 04-29-2011 at 01:40 PM. Reason: ashamed

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are only modifying one object. Are all the objects the same as the last input item? I'd imagine they are. You are storing the references to the objects in the array list. The elements of the array list point to the object on the heap. Since they are all the same item(this), the calls to setXxxx are just modifying the object referenced by this.

    Luckily, there is an easy solution. First, get and store the information in strings, int, other primitives that make up the class. Then create an item with a constructor
    Java Code:
    AddressBook ab = new AddressBook(/*use the stored arguments in the constructor*/);
    vector.add(ab);
    This should work as you want it to.

    edit: I said array list in my explanation, just replace all occurrence of array list with vector.
    Last edited by sunde887; 04-29-2011 at 05:03 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

  4. #4
    paul1024's Avatar
    paul1024 is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default

    ;;;;;;;;;;
    Last edited by paul1024; 04-29-2011 at 01:44 PM.

  5. #5
    paul1024's Avatar
    paul1024 is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default

    Im sorry. I glanced at the forum rules in the past and I didnt remember that rule. I was just trying to get a quick answer.

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I know the post is about a day old, but to the op, don't remove your questions, it could end up answering other peoples questions in the future. Instead mark the thread solved with the thread tools at the top of the page.

Similar Threads

  1. Storing array?
    By LifeElixer in forum New To Java
    Replies: 7
    Last Post: 04-14-2011, 06:10 AM
  2. Storing data?
    By Syntax in forum New To Java
    Replies: 4
    Last Post: 01-23-2010, 01:17 AM
  3. Storing objects directly with db4o
    By german in forum JDBC
    Replies: 0
    Last Post: 05-12-2009, 08:22 PM
  4. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  5. Storing Data
    By Khorod in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 05:48 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
  •