Results 1 to 6 of 6
- 04-17-2008, 03:37 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 31
- Rep Power
- 0
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.
- 04-17-2008, 03:51 PM #2
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
- 04-17-2008, 03:55 PM #3
Member
- Join Date
- Apr 2008
- Posts
- 31
- Rep Power
- 0
hi sanjeev
sorry i have not checked
very very sorry sanjeev for that one
- 04-17-2008, 04:19 PM #4
Member
- Join Date
- Apr 2008
- Posts
- 1
- Rep Power
- 0
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");
}
}
}
- 04-18-2008, 06:59 AM #5
Member
- Join Date
- Apr 2008
- Posts
- 31
- Rep Power
- 0
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
- 04-18-2008, 07:42 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
2 dimensional Lists
By gapper in forum New To JavaReplies: 4Last Post: 01-20-2008, 09:01 AM -
question about linked lists
By jkurth in forum Advanced JavaReplies: 1Last Post: 11-11-2007, 08:33 AM -
Tudu Lists 2.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 08-10-2007, 04:39 PM -
Compare lists
By JavaNoob in forum New To JavaReplies: 2Last Post: 08-08-2007, 03:11 PM -
Tudu Lists 2.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-11-2007, 03:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks