Sweety Bertilla
Sweety Bertilla

Reputation: 1022

Arraylist returns only the first data

I am assigning data from one array list to another. and trying to add it to a new array list. But I could see only one data stored the array list.

public ArrayList<DataCache> getData()   
    { 
        StoreData data = new StoreData(this);

        if(data != null && data.getFeedValue() == 1 && contentOf !=null)
        {
                ArrayList<DataCache> cacheOf = new ArrayList<DataCache>();
                ArrayList<DataCache> cache = new ArrayList<DataCache>();
                System.out.println("Size of ContentOf"+contentOf.size());
                for (int i=0;i<contentOf.size();i++)
                {
                    System.out.println("Value of ContentOf"+contentOf.get(i).mFeed);
                    System.out.println("Value of ContentOf Data"+contentOf.get(i).mFeed.getData());
                    cache = contentOf.get(i).mFeed.getData();
                    if (cache != null && cache.size() > i)
                    {
                        cacheOf.add(cache.get(i));
                        System.out.println("Cache value of "+i+ " is "+ cache.get(i));
                    }

                }
                return cacheOf;
        }
}

Logs:

-03 15:56:34.980: I/System.out(14202): Size of ContentOf3
02-03 15:56:34.990: I/System.out(14202): Value of ContentOfcom.ap.philly.utils.PDCConst$PDCFeed@40a4cc00
02-03 15:56:34.990: I/System.out(14202): Value of ContentOf Data[com.philly.prosportsframework.utils.DataCache@40a7ade0]
02-03 15:56:34.990: I/System.out(14202): Cache value of 0 is com.philly.prosportsframework.utils.DataCache@40a7ade0
02-03 15:56:34.990: I/System.out(14202): Value of ContentOfcom.ap.philly.utils.PDCConst$PDCFeed@408a3490
02-03 15:56:34.990: I/System.out(14202): Value of ContentOf Data[com.philly.prosportsframework.utils.DataCache@40a0d058]
02-03 15:56:34.990: I/System.out(14202): Value of ContentOfcom.ap.philly.utils.PDCConst$PDCFeed@408a3d50
02-03 15:56:34.990: I/System.out(14202): Value of ContentOf Data[com.philly.prosportsframework.utils.DataCache@410dbd78]
02-03 15:56:34.990: I/System.out(14202): %%%%%%  SIZE OF CACHE IS 1

Upvotes: 0

Views: 103

Answers (1)

wanam
wanam

Reputation: 548

Why not using the Arraylist method addAll()?

cache.addAll(cacheOf);

Upvotes: 1

Related Questions