what does list1=list2
and list1==list2
mean when we use ArrayLists?
ArrayList <String> list1, list2;
list1=new ArrayList<>(); list2=new ArrayList<>();
what does list1=list2
and list1==list2
mean when we use ArrayLists?
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.
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.