Compare value in array
How to compare value in array?
e.g. I have Array named list which contains 12 elements.I wanted to compare the value of the array e.g. I wanted to know if index 0 equal or not equal to index 2.
I didnt get the right code. I have tried code:
== only works for numeric values.
use Value1.equals(value2) for strings, or else check the api Array (Java 2 Platform SE v1.4.2)
what list var is? Is it Vector or what
And what type list uses?
don't you need to use square brackets if its an array?
Originally Posted by cassysumandak
If what you calling an "array" is a List (for example an instance of ArrayList), try
The point is that collections contain references to objects, not primitives and those references should be compared using equals(). Additionally you may want to be fussy about the case when list.get(0) is null.
you should better use two loops for that )