Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comaparing two arrays

 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have compare 2 arrays if they have same value then nothing has to done it array A contains and array B does not the have that value then write an insert statement and if array B contains and array A does not contain then write delete statement.

Can this be done in single loop or 2 loops. Can anybody help me to write this logic.

Any help would be apprecicated.

Regards
infyniti.
[ October 21, 2005: Message edited by: infyniti molugu ]
 
Jean-Sebastien Abella
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you know about collection???
if not you might want to look at it, they got those kind of operation

java.util.Collection
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will you process your items in sorted order? That becomes the classic master-update problem back from the days of punch cards when there was no random access and we had to process cards in sequence. It works on infinitely large datasets by reading from two sources (stacks of cards) without holding arrays of items in memory.
 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...but can u please have look what I did is correct...I am unable to use collection for second iteration ......

SelectedRoles is HashMap----that can be see in code
SelectedGroupRoles is String array


connection = getConnection();
//HashMap retrieveSelectedRoles = retrieveSelectedRoles(conn, wfdEntity.getWorkflowId());
HashMap selectedRoles = new HashMap();
selectedRoles.put("1", "Professor");
selectedRoles.put("2", "Guide");
Set keyItr = selectedRoles.keySet();
Iterator itr2 = keyItr.iterator();

for (int i = 0; i < SelectedGroupRoles.length; i++)
{
System.out.println("SelectedGroupRoles[i] :" + SelectedGroupRoles[i]);
if(! (selectedRoles.containsKey(SelectedGroupRoles[i]))){
System.out.println("Insert the key value" + SelectedGroupRoles[i]);
}
}

while (itr2.hasNext())
{
String strKey = (String) itr2.next();
for (int i = 0; i < SelectedGroupRoles.length; i++)
{
flag = false;
System.out.println("the value of gropuroles :" + SelectedGroupRoles[i]);
System.out.println(
"strKey == SelectedGroupRoles[i] :"
+ strKey
+ " == "
+ SelectedGroupRoles[i]);

if (strKey.equals(SelectedGroupRoles[i]))
{
flag = true;
System.out.println("the vlaue of flag : " + flag);
break;
}
}
if (!(flag))
{
System.out.println("Delete the key value " + strKey);
}
}


Regards
Infyniti.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic