jeudi 17 décembre 2020

Java- Which of the following instructions would you use, knowing that myString is of type String and can be null?

I want to hear opinions and arguments on this topic, I'm pretty undecided.

The equals method is the best one for value equality/testing?

1   if (myString.equals("test")) 
2   if ("test".equals(myString)) 
3   if ("test".compareTo(myString) == 0) 
4   if (myString.compareTo("test") == 0)

Aucun commentaire:

Enregistrer un commentaire