Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you create a Java Iterator over a 2d array?

Can you create a single Iterator that will step over all spaces in a 2d array?

like image 594
Takkun Avatar asked Apr 10 '26 03:04

Takkun


2 Answers

If you implement the Iterable interface, you can use a for-each loop. Related examples may be found here.

like image 142
trashgod Avatar answered Apr 12 '26 16:04

trashgod


Yes, wrap the array in an object and make the object implement the iterator interface. So it can be done. I am not aware of any such iterator that ships with the Jdk.

like image 30
Scorpion Avatar answered Apr 12 '26 17:04

Scorpion



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!