Read Java Interview Questions and Answers for Beginners and Experienced

Java Not equals to operator Example

In this Java examples of Java tutorial, we will study about the Java not equals to operator example and see how not equals to operator works.

 


Not Equals to operator

Not equals to operator is one of the Java comparison operator. it is used to evaluate whether some value is not equals to another value or not.

In Java, != is the not equals to operator.

 


Syntax of Not equals to operator

Syntax of != operator in Java is

X != Y;
  • X and Y are two variables under comparison.
  • != is the not equals to comparison operator in Java.

It will returns true if condition is true, otherwise it will returns false.

 


Java != operator Example

Let’s Understand Java not equals to operator by taking an example.

public class JavaExamples {

public static void main(String[] args) {
//Java not equal to Operator Example in Java
String name1="ByteArray.in";
String name2="ByteArray.in";

System.out.println("both Strings are not equals :"+(name1!=name2));

}

}

Output

both Strings are not equals :false


 

Explanation

In above != Java operator example, there are two variables name1 and name2. both having same value. When != operator was applied to them, it returns false, obviously, because both are same.

 

In Nutshell != operator is used to evaluate whether left hand side operand is not equals to right hand side operand. it returns true if both are not equals otherwise it returns false.