[英]Java: list1=list2 // list1==list2?
what does list1=list2
and list1==list2
mean when we use ArrayLists?当我们使用 ArrayLists 时,
list1=list2
和list1==list2
是什么意思?
ArrayList <String> list1, list2;
list1=new ArrayList<>(); list2=new ArrayList<>();
In Java, a single equal sign =
is used to assign values to variables to be used later in your code, this is why it is called the assignment operator.在 Java 中,单个等号
=
用于为稍后在代码中使用的变量赋值,这就是为什么它被称为赋值运算符的原因。
Two equal signs ==
is a comparative operation between two values which returns a Boolean.两个等号
==
是两个值之间的比较运算,它返回一个布尔值。 For instance 1 == 1
will return true
, but I would be careful when using this operation with objects and would suggest using the equals()
or compare()
method.例如
1 == 1
将返回true
,但在对对象使用此操作时我会小心,并建议使用equals()
或compare()
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.