Does Java have Identical Comparison Operator example ===

=== is useful in weak typed languages, such as Javascript, because it verifies that the objects being compared are of the same type and avoids implicit conversions.

=== has absolutely no use in a strongly typed language such as Java because you can't compare variables of different types without writing a specific method for doing this.


For example, if you want to compare an int to a String in Java, you will have to write some special method as such:

boolean compareIntString(int i, String s) {
    return (i == parseInt(s));
}

But this is pretty much overkill. (And as you'll notice, as written, this method only accepts an int and a String. It doesn't accept just any two variables. You know before you call it that the datatypes are different.)

The main point is, that while you can do i == s in Javascript, you can't do i == s in Java, so you don't need ===.


I guess, the short answer is that Java's == is Javascript's ===. If you want to emulate Javascript's == and compare two items, ignoring data type, you'll have to write a custom method which accepts generic data types as arguments... and figure out the logic on comparing, at a minimum, all the possible combinations of Java's primitive data types...


No java does not have === operator. Reason is pretty well explained by nhgrif. Here is the list of operators in java and their precedence:

enter image description here

Source: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

Tags:

Java