Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: v_borchert@despammed.com (Volker Borchert) Newsgroups: comp.lang.java.programmer Subject: Re: Removing an element while iterating over a List with enhanced for? Date: 16 Feb 2017 20:09:15 GMT Organization: Private site at Eddersheim, Germany Lines: 24 Distribution: world Message-ID: References: X-Trace: individual.net BizFCZMZVogbpNGKy7+UcgDx9WJ9ZBaHRkZV9Y0Z/C8gfrP6bn Cancel-Lock: sha1:wEyGxrMb+Z8EW578ytJPbu/H/rQ= Xref: csiph.com comp.lang.java.programmer:36308 Robert Klemme wrote: > On 16.02.2017 18:17, Knute Johnson wrote: > > On 2/15/2017 21:43, Arne Vajh??j wrote: > >> On 2/15/2017 5:56 PM, Knute Johnson wrote: > >>> An enhanced for loop on a List is no different than using an Iterator > >>> right? So is there any problem removing the current element from the > >>> list while using the enhanced for loop? I couldn't find anything that > >>> said it was OK or not OK in the JLS. > >> > >>> List list = Stream.of(1,5,7,9,13).collect(toList()); > > Btw. I know it is just the code to get a list filled but still you can > have that much simpler: > > list = Arrays.asList(1, 5, 7, 9, 13); > > We tend to forget the "good ole code" over all the fancy new things. :-) The list you get from this does not support removal. -- "I'm a doctor, not a mechanic." Dr Leonard McCoy "I'm a mechanic, not a doctor." Volker Borchert