They do almost the same thing.
The only difference is that the first example uses the equal () method of the string object "str" with the parameter "test" -string as a parameter, and the second example uses the equal () method of the string "text" with "str" as the parameter.
The second option cannot throw a NullPointerException because it is clearly not null.
source share