Ritzor
Ritzor

Reputation: 665

java iterator stops unexpectadely

My code to iterate is,

Iterator<BrokerDeals> it = listBrokerDeals.iterator();
ArrayList<BrokerDeals> listBrokerDeals_new = new    ArrayList<BrokerDeals>();
                    while (it.hasNext())
                    {
                        BrokerDeals deals = it.next();
                        Log.i("TRACE==","deals.ok_id"+deals.getOkId());
                        if(!(deals.getOkId().equalsIgnoreCase(null)))
                        {
                            Log.i("TRACE==","deals.ok_id inside cond");
                            listBrokerDeals_new.add(deals);
                        }

                    }

                    Log.i("TRACE==","list broker deals" +listBrokerDeals_new);

My Log is

04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id6321r9hrr960780
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id inside cond
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_idx9crv9119111a
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id inside cond
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_iden27yx79ph6082241a
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id inside cond
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_idkhvu42e929520
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id inside cond
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_iduly4n9b9ne2071111a
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id inside cond
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_idkcis9719n464179
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_id inside cond
04-30 08:20:28.021 28449-28449/com.o.n I/TRACE==: deals.ok_idnull
04-30 08:20:28.871 28449-29253/com.o.n I/qtaguid: Untagging socket 137

As you can see in log ITERATOR STOPS when deals.ok_id() gives null and Log.i("TRACE==","list broker deals" +listBrokerDeals_new); this never gets printed.

Any idea why program is stopping without error?

Upvotes: 0

Views: 38

Answers (1)

CConard96
CConard96

Reputation: 914

Your code for checking if getOkId() is null is wrong.

if(!(deals.getOkId().equalsIgnoreCase(null)))

It should be:

if(!(deals.getOkId() == null))

because that method expects a non-null String. As stated in its JavaDoc:

This method returns true if the argument is not null and the Strings are equal, ignoring case; false otherwise.

Upvotes: 1

Related Questions