Adding a bunch of items to ArrayList correctly

user2219097

I have a major problem with how I am adding items to my list. In the for loop I have constructed, I am not sure how to continually add elements to the list. I keep adding only one element which overwrites the last element in the list. So if I was to add 2 elements to my list, after the loop has finished, my array list size will be 1. I'm not sure how to add items properly. I know exactly where the problem lies but am struggling to find any clever way of adding correctly. Will really appreciate any help

tasklist = db.getAllTasks();
    locationlist = db.getAllLocations();

    for (int i = 0; i < locationlist.size(); i++) {
    task_location_list = db.getAllTasksbyLocation(locationlist.get(i)
                .getAddress());


        for (Task task : task_location_list) {
            task_location_list.add(task);

        }
    }
vipul mittal

try:

 task_location_list =new ArrayList<Task>();
 for (int i = 0; i < locationlist.size(); i++) {
    task_location_list .addAll(db.getAllTasksbyLocation(locationlist.get(i)
                .getAddress()));

    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

adding items to actionbar correctly

From Dev

Adding Onclick() to items in a ArrayList

From Dev

Java Nested ArrayList not Adding Correctly

From Dev

How to stop adding items to the arraylist?

From Dev

Java: trouble adding items to ArrayList<ArrayList<Integer>>

From Dev

Adding a bunch of arrows to a ggmap

From Dev

Adding a Preloader to an Bunch of Images

From Dev

Adding a Preloader to an Bunch of Images

From Dev

Adding text to a bunch of files

From Dev

adding PATHs for a bunch of programs

From Dev

Big-O run time for adding N items into ArrayList

From Dev

Adding items to ArrayList using a for loop throws outofbounds exception

From Dev

Perl XML::XPath adding a bunch of junk to the document

From Java

RecyclerView not displaying ArrayList correctly

From Dev

Arraylist not removing object correctly?

From Dev

Arraylist is not correctly parsed

From Dev

Adding integer arraylist to arraylist in android

From Dev

Adding an arrayList of random type to an arrayList

From Dev

adding arrayList to arraylist using loop

From Dev

Adding an arrayList of random type to an arrayList

From Dev

ArrayList.add() not adding to ArrayList

From Dev

Adding string to ArrayList<ArrayList<String[]>>

From Dev

Items of RecyclerView are not showing correctly

From Dev

Items of RecyclerView are not showing correctly

From Dev

list items not displaying correctly

From Dev

Adding to vectors correctly

From Dev

Position wrapped flex items prefer to group/bunch at the end of the container

From Dev

Moving several items in an ArrayList

From Dev

Control selected items of an ArrayList