String Compare by Operator in Java



You can compare two strings using == operator. But, it compares references of the given variables, not values.

Example

Live Demo

public class Sample {
   public static void main(String args[]){
      String str1 = "hello";
      String str2 = "hello";
      System.out.println(str1 == str2);
   }
}

Output

true
Updated on: 2020-02-26T06:23:02+05:30

136 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements