I am a new-comer in Java and in process of learning. I need a an answer of following question supported with valid theory. Consider the following line-
Iterat
You can define the return type of your Iterator beforehand. As you declare the iterator, you can (and should) define the type of your list items like this:
Iterator
So when you access itr
you don't have to cast to file, e.g. (File) itr.next()
but can directly use it in your while loop:
while (it.hasNext()) { File f = itr.next() }
Your compiler now won't complain when using next().