Timeline for Java - adding elements to list while iterating over it
Current License: CC BY-SA 3.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 18, 2016 at 7:41 | review | Low quality answers | |||
| Jan 18, 2016 at 9:15 | |||||
| Jul 24, 2012 at 4:51 | comment | added | user545680 |
@stacker If you read the code again, you'll find that will cause duplicates. If you want to store it in the first list, you would do originalList = newList;. That doesn't particularly matter though, as JimN's solution is better for the add(T) operation.
|
|
| Jul 24, 2012 at 4:37 | comment | added | stacker | originalList.addAll( newList ); should be added. | |
| Jul 24, 2012 at 4:37 | comment | added | Trup | Isn't there anything more practical? This will be a repeated operation, I want to avoid copying so much. Or should I just use a temporary list for the new objects and merge the 2 lists at the end? | |
| Jul 24, 2012 at 4:35 | history | answered | user545680 | CC BY-SA 3.0 |