Re: Java collections




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

.



Relevant Pages

  • Re: Java collections
    ... object and when the Cust object changes, ... 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? ...
    (comp.lang.java.programmer)
  • Re: Counting Occurences Between Dates
    ... I have data that contains a variety of dates that I have sorted by date. ... am trying to count the nuber of occurences in a given month. ... Customer x 1/1/07 ... Total occurences for this customer would equal 5. ...
    (microsoft.public.excel.worksheet.functions)
  • SUMPRODUCT problem
    ... I am trying to obtain a sum for rows where two conditions are true. ... number sold to a certain customer. ... That is to say it can find 10 occurences of ... Why is my first formula not working and providing me a sum of payments ...
    (microsoft.public.excel.misc)