• Post Reply Bookmark Topic Watch Topic
  • New Topic

List.iterator() or List.size()  RSS feed

 
Ranch Hand
Posts: 1084
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a List and I want to Iterate the elements and I can do it in either way.

for(Iterator it=list.iterator();it.hasNext() ;)
{
// my processing with it.next()
}

or

for(int i=0;i < list.size();i++)
{
// Processing with list.get(i)
}




which one should be preffered ??

thanks
Shailesh
[ February 04, 2005: Message edited by: Shailesh Chandra ]
 
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.Here's an excellent writeup that discusses speed concerns in accesing List elements as well as the jdk1.4 introduced RandomAccess marker interface.

ram
 
Shailesh Chandra
Ranch Hand
Posts: 1084
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ramprasad !!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!