Syed Qasim Ahmed
Syed Qasim Ahmed

Reputation: 1362

What is the efficient way to compare a ArrayList of String in android

I want to compare each item of an arraylist to the item of another arrayList It seems to slow. How to speed up this code. I want char by char comparision of each string.

Please suggest me if any loop is unnecessary here.

public static void FinalGroups(ArrayList<ArrayList<QuineMCCluskyModel>> Prime_Implicants,
                                   ArrayList<ArrayList<QuineMCCluskyModel>> FinalGRoupImplicants)
    {
        Integer count = 0;

        for (Integer i = 0; i < Prime_Implicants.size(); i++)
        {
            for (Integer j = 0; j < Prime_Implicants.get(i).size(); j++)
            {

                if (i + 1 < Prime_Implicants.size())

                    for (Integer L = 0; L < Prime_Implicants.get(i+1).size(); L++)
                    {
                        count = 0;
                        if (Prime_Implicants.get(i).size() > 0 && Prime_Implicants.get(i+1).size() > 0)
                        {
                            for (Integer k = 0; k < Prime_Implicants.get(i).get(j).Number.length()  ; k++)
                            {

                                if (Prime_Implicants.get(i).get(j).Number.charAt(k)
                                        != Prime_Implicants.get(i+1).get(L).Number.charAt(k))
                                {

                                    count++;
                                }

                            }
                            if (count == 1)
                            {
                                while (i + 1 > FinalGRoupImplicants.size())
                                    FinalGRoupImplicants.add(new ArrayList<QuineMCCluskyModel>());
                                QuineMCCluskyModel temp_model = new QuineMCCluskyModel();
                                temp_model.Number = "";
                                temp_model.HasUsed = false;
                                for (Integer k = 0; k < Prime_Implicants.get(i).get(j).Number.length()
                                     ; k++)
                                {

                                    if (Prime_Implicants.get(i).get(j).Number.charAt(k)
                                            == Prime_Implicants.get(i+1).get(L).Number.charAt(k))
                                    {
                                        temp_model.Number += Prime_Implicants.get(i).get(j).Number.charAt(k);
                                    }
                                    else
                                    {
                                        temp_model.Number += 'b';
                                    }


                                }

                                Prime_Implicants.get(i).get(j).HasUsed = true;
                                Prime_Implicants.get(i+1).get(L).HasUsed = true;
                            }


                        }
                    }
            }
        }

Upvotes: 1

Views: 72

Answers (1)

RussHWolf
RussHWolf

Reputation: 3654

Try using int types rather than Integer. You should see some performance increase from avoiding Autoboxing

Upvotes: 1

Related Questions