java not equals()
时间: 2024-05-20 16:17:42 浏览: 68
java中equals和==的区别.doc
The not equals operator in Java is represented by the symbol "!=". It is used to compare two values and returns true if they are not equal, and false if they are equal.
For example:
int a = 5;
int b = 6;
if(a != b) {
System.out.println("a is not equal to b");
}
This code will output "a is not equal to b" because the values of a and b are not equal.
The not equals operator can also be used with strings:
String str1 = "hello";
String str2 = "world";
if(!str1.equals(str2)) {
System.out.println("str1 is not equal to str2");
}
This code will output "str1 is not equal to str2" because the values of str1 and str2 are not equal. Note that when comparing strings, the equals() method should be used instead of the == operator.
阅读全文