• Post Reply Bookmark Topic Watch Topic
  • New Topic

Recursive file listing in java  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


May someone explain about for loop?
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the advantage of using this for?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:What is the advantage of using this for?

1. Easy to use : you don't need to cast, you don't need a counter, you don't need an iterator...
2. Easy to read
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Easy to use : you don't need to cast, you don't need a counter, you don't need an iterator...


and faster?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:and faster?

Which one will execute Faster Enhanced for loop or For loop?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Were you actually asking about the syntax of the enhanced for loop, or are you asking a question about recursion?

Note that in line 7, the method is calling itself - that's recursion.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:

One warning: even though f is a directory listFiles() can still return null, if you don't have the rights to read the folder contents. A few system folders (like those for system restore) can never be read. If you don't check for null the for-loop will cause a NullPointerException.
 
Campbell Ritchie
Marshal
Posts: 55770
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote: . . . and faster?
Why on earth are you worrying about speed of execution at this stage?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!