D
D
Djus12021-06-08 22:03:54
Java
Djus1, 2021-06-08 22:03:54

How to remove all elements and not just the first Java?

Hello!

I am a complete newbie to Java. Help me please!

There is a code, it removes all selected items

var campaignIterator = AdWordsApp.campaigns()
        .get();
    if (campaignIterator.hasNext()) {
        var campaign = campaignIterator.next();
        var locationIterator = campaign.targeting().targetedLocations().get();

        while (locationIterator.hasNext()) {
            var loc = locationIterator.next();
            loc.remove();
        }
    }


And there is my code, it only removes the first one, how can I repeat the code above?

var campaignMobileAppIterator = campaign.extensions().mobileApps().get();
var campaignMobileApp = campaignMobileAppIterator.next();

campaign.removeMobileApp(campaignMobileApp);


I tried just adding hasNext but something now doesn't delete at all. I can just repeat this script a bunch of times, well, something is not comme il faut.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-06-08
Hasanly @azerphoenix

Good afternoon.
Well hasNext() returns boolean if there is a next element. next() gets the next element.
Accordingly, as in the first example, you first check if there is a next element, and then get it and delete it. Roughly speaking, you need to iterate over the campaignIterator and then remove each element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question