|
-
Jun 2nd, 2002, 01:19 PM
#1
Thread Starter
New Member
how to compare two arraylists?
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?
-
Jun 2nd, 2002, 02:06 PM
#2
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 
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?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jun 2nd, 2002, 04:59 PM
#3
Dazed Member
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");}
}
}
Last edited by Dilenger4; Jun 2nd, 2002 at 05:04 PM.
-
Jun 3rd, 2002, 06:17 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|