jeudi 28 mai 2015

Shortening if() with string.equals method

Is there any way to shorten this if() statement? To avoid repeating string.equals() somehow?

else if (extension.equals("jpg") || extension.equals("JPG") || extension.equals("png") || extension.equals("PNG") || extension.equals("bmp") || extension.equals("BMP") || extension.equals("jpeg") || extension.equals("JPEG"))
            {
                tmp.setIcon(new ImageIcon(getClass().getResource("/menage/Resources/imageIco.png")));
            }

To something looking similar to this :

    else if (extension.equals(("jpg")||("JPG")||("png")||("PNG")||("bmp")||("BMP")||("jpeg")||("JPEG")))
    {
    tmp.setIcon(new ImageIcon(getClass().getResource("/menage/Resources/imageIco.png"));)
    }

I am aware that this question looks odd, however if() with such long conditions list is unclear and requires a lot of writing as well.

Aucun commentaire:

Enregistrer un commentaire