Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2008, 04:37 PM
Member
 
Join Date: Apr 2008
Posts: 31
Rep Power: 0
raj reddy can only hope to improve
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 04:51 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 254
Rep Power: 2
sanjeevtarar is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 04:55 PM
Member
 
Join Date: Apr 2008
Posts: 31
Rep Power: 0
raj reddy can only hope to improve
Default
hi sanjeev

sorry i have not checked

very very sorry sanjeev for that one
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 05:19 PM
Member
 
Join Date: Apr 2008
Posts: 1
Rep Power: 0
harivaram is on a distinguished road
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");
}

}

}
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-18-2008, 07:59 AM
Member
 
Join Date: Apr 2008
Posts: 31
Rep Power: 0
raj reddy can only hope to improve
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-18-2008, 08:42 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,256
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
A simple way I used to test this. See you can get the logic for your application.

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);
            }
        }
    }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 dimensional Lists gapper New To Java 4 01-20-2008 10:01 AM
question about linked lists jkurth Advanced Java 1 11-11-2007 09:33 AM
Tudu Lists 2.1 JavaBean Java Announcements 0 08-10-2007 05:39 PM
Compare lists JavaNoob New To Java 2 08-08-2007 04:11 PM
Tudu Lists 2.0 JavaBean Java Announcements 0 07-11-2007 04:32 PM


All times are GMT +2. The time now is 05:27 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org