tag:blogger.com,1999:blog-38892787.post5015193719170501739..comments2023-04-16T11:32:55.171+02:00Comments on loxal DEV: For-each loop vs Iterator vs C-style for loopUnknownnoreply@blogger.comBlogger3125tag:blogger.com,1999:blog-38892787.post-88149003663447603482014-04-22T20:57:28.850+02:002014-04-22T20:57:28.850+02:00Great. Good point made here, but it completely dep...Great. Good point made here, but it completely depends on the underlying data structure. Some data structure takes O (n) for get (I) where as some take O (1). So performance benifit will depend on the underlying data structure if we are using old c style loop.<br />Here one point is worth making that using iterator we'll always have the complexity of O (1) for the next() as it is the basic requirement for all the iterators. I personally prefer for each style(if no removal is required) as it has no boilerplate code and provides same performance as of the iterator.Abhishek Kumarhttps://www.blogger.com/profile/17469253122427964201noreply@blogger.comtag:blogger.com,1999:blog-38892787.post-87729962217012988712014-04-22T01:18:00.766+02:002014-04-22T01:18:00.766+02:00Thanks Francois, you're right. I've change...Thanks Francois, you're right. I've changed the implementation to use LinkedList, which is still not quite O(n) but fore sure > O(1).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-38892787.post-19960415175833975842014-04-22T00:18:27.651+02:002014-04-22T00:18:27.651+02:00 looking on the code of asList, it seems to me tha... looking on the code of asList, it seems to me that the get(index) is o(1) as it uses an array undercover<br />Anonymoushttps://www.blogger.com/profile/03316983889818832622noreply@blogger.com