String is a sequence of characters. In Java, objects of String are immutable which means they are constant and cannot be changed once created.
Using equals, the result is true because its only comparing the values given in s1 and s2.
In simple words, == checks if both objects point to the same memory location whereas .equals () evaluates to the comparison of values in the objects.
In general both equals () and “ == ” operator in Java are used to compare objects to check equality but here are some of the differences between the two:
The following code shows how to compare two strings in R to determine if they’re equal:
The following code shows how to use the identical () function to determine if two vectors of strings are equal:
The following code shows how to use the %in% operator to find which strings in one vector belong to another vector: