Re: Whats wrong with this code....




"John McGrath" <ng@xxxxxxxxxxxxx> wrote in message
news:xn0e0ov2e5087vl009@xxxxxxxxxxxxxxxxxxx
> On 4/6/2005 at 6:58:43 PM, is0871@xxxxxxxxx wrote:
>
> > If you can figure out whats wrong in the above code(wihout compiling)
>
> One obvious problem is that you are iterating over a collection and
> adding to the same collection in the process. This will result in a
> ConcurrentModificationException.

You're quite right that adding to a collection while iterating over it is
usually a bad idea, although I don't think it's possible to tell exactly
what will happen because we don't know the actual class for either the
iterator or the collection. Aside from compilation errors, without knowing
what the fragment is supposed to do it's impossible to say how it might be
wrong.

Cheers,
Matt Humphrey matth@xxxxxxxxxxxxxx http://www.iviz.com/


.



Relevant Pages

  • Re: Whats wrong with this code....
    ... > If you can figure out whats wrong in the above code(wihout compiling) ... One obvious problem is that you are iterating over a collection and ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Visual Web Developer Express
    ... delpoy a test app to a remote web server, but compiling my project doesn't ... Is this because it's an express edition or whats the deal? ... Prev by Date: ...
    (microsoft.public.vstudio.general)
  • Re: Finding *unique* entries in a list
    ... A simple solution is creating an empty list, iterating over your items ... in the list of items and, by using a Hashtable, do lookups for each ... Greg ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Permuatations [was: Please Help!!Daughter...]
    ... >I think there's a faster way to do it by shifting the bits instead of ... >iterating the value. ... http://mindprod.com Java custom programming, consulting and coaching. ... Prev by Date: ...
    (comp.lang.java.programmer)
  • adding elements to the end of the list
    ... given a list a and element b whats the fastest way to add the element ... tconc procedure does not work if the list is not built using the ... one of the ways I can think of without iterating over the list is, ... Are there any faster methods? ...
    (comp.cad.cadence)