Results 1 to 4 of 4

Thread: how to compare two arraylists?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    Germany
    Posts
    7

    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?

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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:
    1. Dim x, y As ArrayList
    2.         If x Is y Then
    3.              Beep()
    4.         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!!

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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");} 
    
        }
       }

  4. #4
    Tygur
    Guest
    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
  •  



Click Here to Expand Forum to Full Width