java - Comparing items in a String Array with items in an ArrayList of Hashmaps -
so have 2 string arrays:
string[] = {"tony", "33", "male", "new york"}; string[] b = {"john", "33", "male", "chicago"};
then have arraylist of hashmaps:
arraylist<hashmap<string, string>> list = [{"name": "john", "age": "33", "gender": "male", "city": "chicago"}], [{"name": "tony", "age": "33", "gender": "male", "city": "new york"}];
so array or b first method. want compare 'name' or value @ index 0 in string or b same 'name' value in arraylist, string or b value @ index 1 '33' same 'age' value in arraylist , forth. have tried following:
for(int = 0; <= list.size(); i++) { assertequals(b[0], list.get(i).get("name")); assertequals(b[1], list.get(i).get("age")); assertequals(b[3], list.get(i).get("city")); }
but problem is, works 1 of string lists, i.e. work if string b first because @ = 0, arraylist has same values of string b.
string[] = {"tony", "33", "male", "new york"}; list<map<string, string>> listofmaps = ...; boolean found = false; for(final map<string, string> map : listofmaps) { if(a[0].equals(map.get("name")) && a[1].equals(map.get("age")) && a[2].equals(map.get("gender")) && a[3].equals(map.get("city"))) { found = true; break; } } if(!found) { // raise alarm - nothing matched }