<> 和 != 比较运算符的区别?
Difference between <> and != comparison operators?
<> 和 != 运算符有什么区别。两个运算符执行相同的操作。
什么时候使用 <> ?和
什么时候使用 != ?
<>
不用于Java中的比较。 !=
是。
<>
(菱形运算符)自 Java 7 起在泛型类型初始化中使用。例如:
List<String> list = new ArrayList<>;
因为您添加了 sqlite
标签:他们 mean the same thing:
Note that there are two variations of the equals and not equals operators. Equals can be either =
or ==
. The non-equals operator can be either !=
or <>
.
事实上,这似乎是跨语言的共同主题:在允许两者的语言中,它们的意思相同。 (下面有各种参考资料。)
有些语言只允许其中一种。在 Java 中,您使用 !=
而 "not equals;" 不能使用 <>
(它有其他含义,并且在不同的上下文中使用)。在 VB.Net 中,情况正好相反:<>
有效,而 !=
无效。
但是很多语言都允许:
T-SQL and MySQL's variant of SQL (and Oracle seems to have both and a couple more). In all three cases, they're different ways of writing the same thing. The Wikipedia page on SQL says <>
is standard, but most rDBMS's also allow !=
.
PHP supports both,他们的意思又是一样的。
So does Python(同样它们是同一件事)。
<> 和 != 运算符有什么区别。两个运算符执行相同的操作。
什么时候使用 <> ?和 什么时候使用 != ?
<>
不用于Java中的比较。 !=
是。
<>
(菱形运算符)自 Java 7 起在泛型类型初始化中使用。例如:
List<String> list = new ArrayList<>;
因为您添加了 sqlite
标签:他们 mean the same thing:
Note that there are two variations of the equals and not equals operators. Equals can be either
=
or==
. The non-equals operator can be either!=
or<>
.
事实上,这似乎是跨语言的共同主题:在允许两者的语言中,它们的意思相同。 (下面有各种参考资料。)
有些语言只允许其中一种。在 Java 中,您使用 !=
而 "not equals;" 不能使用 <>
(它有其他含义,并且在不同的上下文中使用)。在 VB.Net 中,情况正好相反:<>
有效,而 !=
无效。
但是很多语言都允许:
T-SQL and MySQL's variant of SQL (and Oracle seems to have both and a couple more). In all three cases, they're different ways of writing the same thing. The Wikipedia page on SQL says
<>
is standard, but most rDBMS's also allow!=
.PHP supports both,他们的意思又是一样的。
So does Python(同样它们是同一件事)。