Android – Compare two List values in android

android, equals, list, string

Dear all i am comparing two List in android if both values are same and it is returning true that is fine but i want to know how many values have been correct between the list string if it is not matching how to achieve this Help is appreciated. Below is my code.

            List<String> list1 = new ArrayList<String>(i1.values());            ///list 1 = [-ful; to be full of; play; playful; full of play]    List<String> acct_Rte_Cdes_A = Arrays.asList(result) ;            ///acct_Rte_Cdes_A  = [-ful; to be full of; play; playful; full of play]             if (list1.equals(acct_Rte_Cdes_A)) {                 // do what you want to do if the string is there                //System.out.println("True");     }  else {        System.out.println("False");         }

Best Solution

Use Collection#retainAll(). like

List<Integer> common = new ArrayList<Integer>(listA);common.retainAll(listB);// common now contains only the elements which are contained in listA and listB.

So you can check for size if it is greater than 0 it meanse some elements are common. And which are common elements common will tell.