mardi 19 septembre 2017

Alternate way for nested ifs using Boolean in Java

I have below block of code

if(Objects.nonNull(isMine)) {
    if (isMine) {
             this.books= this.myList;
    } else  {
            this. books= this.notMyList
    }

 } else {
     this. books = this.allList
 }

isMine - is a Boolean object I tried with switch case by converting isMine to a string as below

 String.valueOf(isMine) 

But didn't work .Suggest a better and faster way to implement above code in java.

Aucun commentaire:

Enregistrer un commentaire