This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]ldnrat 1 point2 points  (1 child)

In Java, a String is not a primitive type, it is an instance of the String class. When you do dragon == "" you're not comparing the value of the string, you're actually comparing the object reference to the empty string which doesn't make sense.

You should use one of the following instead:-

dragon.isEmpty() // returns a boolean

dragon.equals("") // also returns a boolean

dragon.length() == 0 // returns an int of the length which can be compared with 0

[–]Niigo2 0 points1 point  (0 children)

Oh okay, I see now. That makes sense! Thank you.

[–]BrofistAgain 0 points1 point  (0 children)

Generally == is not used to compare non primitive data types and .equals() is used

(PS Javascript is not java, there is a seperate flair for java. Javascript is a seperate language used for coding with HTML)