Using Arraylist in Java -
I have a problem using the arrays in Java, my code looks like this:
list & lt; Integer & gt; Number 1 = new Arsuachi & lt; & Gt; (); & Lt; Integer & gt; Number 2 = new Arrielast & lt; & Gt; (); Boolean beacomphere; I add lists to the same number, but when I try to compare the index number of lists 0, the result of the boolean is false when it should be correct: / P>
bcompare = numbers1.get (0) == numbers 2. get (0); bcompare is false
But here's some thing when I use some temp variables and then compare them to what it does, what I expect, a true on bcompare Value:
int a = number 1.get (0); Int b = numbers2.get (0); Bcompare = a == b; The bcompare is true
What am I doing wrong here? The reason for this is that if you use wrapper classes integer, a ==
Comparison of "context" to compare values of objects, use equal () method: bcompare = numbers1.get (0) ) .equals (numbers2.get (0)); The second comparison is correct, because int is a primitive type and has only value
int and For more information about the difference between integer , see
Comments
Post a Comment