As discussed, you should use `itr.hasNext`.