Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Shailesh Chandra
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 ]
 
ramprasad madathil
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 !!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!