mardi 7 avril 2020

Do the methods used in if statement tests execute?

Disclaimer: I am a new programmer with only a few months of experience so I apologize if this question is trivial.

In Java, do the methods in the test of an if statement execute? For example, in this snippet of code, I have a waitlist variable of type LinkedListQueue, which is a class that I wrote to model a queue data structure, with methods for enqueue() (add), dequeue() (remove), size, setCapacity, and isEmpty(). The dequeue() method returns the object removed from the queue. The waitlist variable is a LinkedQueue object of type int. I want to traverse through each element of the queue and check if it equals 3, and if it does, I will remove it. When the line of code for the if statement test executes, does it remove the object in the queue?

for (int i = 0; i < waitlist.size(); i++) {
            if (waitlist.dequeue() == 3) {
                waitlist.dequeue();
            }
    }

Aucun commentaire:

Enregistrer un commentaire