Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How shall I declare Iterator?

Tags:

java

iterator

Which form is preferred:

String my = "Which form shall I use?";
Iterator iter = my.iterator();

or

Iterator<String> iter = my.iterator();

I personally preferr the former but in my materials from uni they use the latter.

like image 399
There is nothing we can do Avatar asked Jul 03 '26 14:07

There is nothing we can do


1 Answers

In the latter form, the Iterator is strongly typed which is preferable

like image 89
ob1 Avatar answered Jul 05 '26 03:07

ob1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!