jeudi 14 mai 2015

Should you create variables for a if statement?

I was wondering, what technically would be the most efficient way.

What would be smarter to code with:

    if (args[0].toLowerCase().toString().equals("server")) {
        System.out.println("SERVER");
    }

Or:

        String host = args[0].toLowerCase();                                                                       
    if (host.equals("server")) {
        System.out.println("SERVER");
    }

Keep in mind, I know that this variable is redundant. And that a argument can also contain a number, but that is not the case of my question. It's just a example.

When should you create a variable for a if statement? Always? Is it safer? Should I do it not, because I am wasting memory? Does it impact the performance at all?

Aucun commentaire:

Enregistrer un commentaire