dimanche 26 mai 2019

Java, convert Ternary operator to IF ELSE

I am sure this repeats something, but yet due to short time I have to ask you straight forward help. How to convert Ternary (: and ?) operator into IF-ELSE statement in Java?

public Integer get(Integer index) {
    if (first == null) {
        return null;
    }
    MyNode curNode = first;
    while (index >= 0) {
        if (index == 0) {
            return curNode == null ? null : curNode.getValue();
        } else {
            curNode = curNode == null ? null : curNode.getNext();
            index--;
        }
    }
    return null;
}

Aucun commentaire:

Enregistrer un commentaire