Results 1 to 6 of 6
  1. #1
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default please i need the code of comparing these two array lists.

    Hi

    There were two arraylists


    List al1 = (List) classabc.fetchTicketpanel();
    System.out.println("THE LATEST VALUES OF THE TICKET KEY1 IS " + al1 );

    List al2 = (List) classabc.fetchDrawresults();
    System.out.println("THE LATEST VALUES OF THE TICKET KEY2 IS " + al2 );


    Think it as a1,a2,a3,a4,a5 are the elements of al1 and b1,b2,b3,b4,b5,b6,b7,b8,b9,b10.........n number of elements

    of al2.


    how to compare the elements of these two arraylists.

    please i need the code of comparing these two array lists.

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Hello Raja,

    you have already posted this problem then why are you creating duplication.

    And other thing is that you have posted again in wrong forum.......IT IS JSP FORUM.



    sanjeev

  3. #3
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    hi sanjeev

    sorry i have not checked

    very very sorry sanjeev for that one

  4. #4
    harivaram is offline Member
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Default to compare two arraylist

    u can use following code to check two arraylists

    import java.util.*;
    public class Ex {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    ArrayList al1=new ArrayList();
    al1.add("a1");
    al1.add("a2");
    al1.add("a3");
    ArrayList al2=new ArrayList();
    al2.add("b1");
    al2.add("a2");
    al2.add("a3");


    if(al1.size()==al2.size()){
    Object[] o1=al1.toArray();
    Object[] o2=al2.toArray();
    if(Arrays.equals(o1,o2)){
    System.out.println("Both arraylists are equal");
    }else{
    System.out.println("Both arraylists are not equal");
    }
    }
    else{
    System.out.println("Both arraylists are not equal");
    }

    }

    }

  5. #5
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    Hi Harivaram

    Thks for your reply

    Actually i need to compare the elements of al1,al2.

    ie a1,a2,a3,a4,a5 are the elements of al1 and b1,b2,b3,b4,b5,b6,b7,b8,b9,b10.........n number of elements

    of al2.

    can u give me the code of comparing this two elements of these arraylists

    Regards
    raja

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    A simple way I used to test this. See you can get the logic for your application.

    Java Code:
        public static void main(String[] args) {
            // TODO code application logic here
            ArrayList list1 = new ArrayList();
            list1.add("a1");
            list1.add("a2");
            list1.add("a3");
            
            ArrayList list2 = new ArrayList();
            list2.add("b1");
            list2.add("a2");
            list2.add("a3");
            
            for (int i = 0; i < list1.size(); i++){
            String str1 = (String) list1.get(i);
                for (int j = 0; j < list2.size(); j++){
                    String str2 = (String) list2.get(j);
                    int result = str1.compareTo(str2);
                    if (result == 0) 
                        System.out.println(str1+  " = " + str2);
                    else if (result > 0) 
                        System.out.println(str1+  " > " + str2);
                    else if (result < 0) 
                        System.out.println(str1+  " < " + str2);
                }
            }
        }

Similar Threads

  1. 2 dimensional Lists
    By gapper in forum New To Java
    Replies: 4
    Last Post: 01-20-2008, 10:01 AM
  2. question about linked lists
    By jkurth in forum Advanced Java
    Replies: 1
    Last Post: 11-11-2007, 09:33 AM
  3. Tudu Lists 2.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 08-10-2007, 05:39 PM
  4. Compare lists
    By JavaNoob in forum New To Java
    Replies: 2
    Last Post: 08-08-2007, 04:11 PM
  5. Tudu Lists 2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-11-2007, 04:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •