Re: Java collections
- From: "Arvind" <asrinivasan@xxxxxxxxxxxxx>
- Date: 3 May 2006 12:32:39 -0700
tim@xxxxxxxxxxxxx wrote:
The only thing I can think of is the collection points to the Cust
object and when the Cust object changes, all occurences in the
collection change as well since they are all pointing to the same
object.
You guessed right
But how does adding a new Customer each time help? Do the old ones hang
around being pointed to by the various occurences of the collection?
Customer cust = new Customer, effectively means that you now have a new
object and new set of values.
If you did not do a new Customer(), then the equivalent in a database
would be a single row of data - so think of what would happen in that
case ! - you keep overwriting the same row - and hence you will be left
with last row of data only.
When you do a new Customer(), you are informing the collection that it
is new object which has different set of values. database equivalent
being, you have created a new row in the table
--
Arvind
.
- Follow-Ups:
- Re: Java collections
- From: tim@xxxxxxxxxxxxx
- Re: Java collections
- References:
- Java collections
- From: tim@xxxxxxxxxxxxx
- Re: Java collections
- From: Vova Reznik
- Re: Java collections
- From: tim@xxxxxxxxxxxxx
- Re: Java collections
- From: tim@xxxxxxxxxxxxx
- Java collections
- Prev by Date: Re: Java collections
- Next by Date: Re: Java collections
- Previous by thread: Re: Java collections
- Next by thread: Re: Java collections
- Index(es):
Relevant Pages
|