hi!
I have a question: how can I compare two ArrayLists?
Example:
dim x as ArrayList
dim y as ArrayList
if not x is y then beep() 'It doesn't work!!!
can anybody help me?
Printable View
hi!
I have a question: how can I compare two ArrayLists?
Example:
dim x as ArrayList
dim y as ArrayList
if not x is y then beep() 'It doesn't work!!!
can anybody help me?
Hi, I have no clue whatsoever what's an ArrayList. I tried this code and it LOOKS LIKE that it's working. But again I have no clue whether you should use it or not :D
VB Code:
Dim x, y As ArrayList If x Is y Then Beep() End If
maybe your code doesnt work becuase you have the Not opperator there? you sure you want it to be there? :D
Here is a small example written in Java that should help you to get the gist of how to compare refrence types in Visual Basic since im pretty sure Visual Basic works the same. The main point is that the == equality operator(in java) tests for refrence equality not wether the contents are equal. The equals(object)method tests for object content equality not refrence. You will also see the the = (equality operator in Visual Basic) is overloaded to compare two strings for content not refrence. Visual Basic has an Equals(Object) method within it's System.Object namespace that im pretty sure you can use to test for equality other than refrence.
Code:import java.util.*;
public class compare{
public static void main(String[] args){
Vector v1 = new Vector();
Vector v2 = new Vector();
v1.addElement("Hello");
v2.addElement("Hello");
// should only be equal in contents
if(v1 == v2){System.out.println("v1 and v2 are equal in refrence");}
if(v1.equals(v2)){System.out.println("v1 and v2 are equal in contents");}
v1 = v2;
// should now be equal in refrence and contents.
if(v1 == v2){System.out.println("v1 and v2 are equal in refrence");}
if(v1.equals(v2)){System.out.println("v1 and v2 are equal in contents");}
}
}
That Not is definitely not the source of your problem. By the way, what do you mean when you say it doesn't work? Does it give you an error or does it just give unexpected results?
If it doesn't give an error, then your problem could be the fact that two different arraylists might have the same values and that could be what you're looking for. In that case, you might have to loop through both arraylists and compare each value.