accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher <ctubb...@apache.org>
Subject Re: hasNext throws weird exception
Date Thu, 19 Nov 2015 16:41:45 GMT
Different scanner.iterator() executions will refer to separate
iterations. The first code should be modified to look like:

Iterator iter = scanner.iterator();
while (iter.hasNext()) { ... iter.next() ...}

Only then would it be the same as the foreach syntax you showed.

--
Christopher L Tubbs II
http://gravatar.com/ctubbsii


On Thu, Nov 19, 2015 at 10:15 AM, z11373 <z11373@outlook.com> wrote:
> Hi Josh,
> This one seems weird however, and this time is not my mistake with 99%
> certainty :-)
>
> When I wrote my code like this:
> while (scanner.iterator().hasNext()) { // call scanner.iterator().next()
> somewhere }
>
> The hasNext() somehow never got evaluated to true. Then I changed the code
> becomes:
>
> for (Map.Entry<Key, Value> entry : scanner) { // do something with entry var
> }
>
> It works fine. I'd think both should behave same, right?
>
>
> Thanks,
> Z
>
>
>
> --
> View this message in context: http://apache-accumulo.1065345.n5.nabble.com/hasNext-throws-weird-exception-tp15586p15598.html
> Sent from the Developers mailing list archive at Nabble.com.

Mime
View raw message