vendredi 3 juillet 2015

how to assign a char to an variable on the base of the size of an ArrayList in Java?

I try to make an long if-statement more compact; this is how it is originaly:

char x;
if(list.size()== 1){
    x = 'a';
}
if(list.size()== 2){
    x = 'b';
}
if(list.size() == 3){
    x = 'c';
}
if(list.size() == 4){
    x= 'd';
}

Is there a possibility to compact this code?

thanks already, Jari Van M

Aucun commentaire:

Enregistrer un commentaire