Sunday 10 January 2016

Compare two array of different length



Here is the code to compare two json array and add to one
conside
notiarray is a json array with json length 10
jarray is a json array with json length 5

boolean found;  
int i=0;
for ( i = 0; i < notiarray.length(); i++)
{
  found = false;
  for (int k = 0; k < jarray.length(); k++){
      if(notiarray.getJSONObject(i).getString("notification_id").equalsIgnoreCase(jarray.getJSONObject(k).getString("key")))
      {
        System.out.println(jarray.getJSONObject(k).getString("key")+ " is equal to " + notiarray.getJSONObject(i).getString("notification_id"));
        found = true;
        break;
      }
  }
  if (!found){
 
      messagelist.add(mn);
  }

}

No comments:

Post a Comment