Removing an ArrayList's elements

I am new to using ArrayList's in java. I have several lists and want to write a method for removing a list with its elements. Here is what I have so far:

public void delete(double value){
    list.remove(value);
}

After that I want get the output:

public ArrayList<Double> getlist(){
    return list;
}

Answers


So lets assume you have a few ArrayLists like this...

ArrayList list1;
ArrayList list2;
ArrayList list3;

Are you saying that, depending on a given value, you want to remove one of these lists? So something like this...

public void deleteList(ArrayList listToRemove){
    listToRemove = null;
}

public void chooseListToRemove(int listNumber){
    if (listNumber == 1){
        deleteList(list1);
    }
    else if (listNumber == 2){
        deleteList(list2);
    }
    else if (listNumber == 3){
        deleteList(list3);
    }
}

Is this what you're trying to do?

Otherwise, are you saying you have a single ArrayList that contains many other lists...

ArrayList allLists;
allLists.add(new ArrayList());
allLists.add(new ArrayList());
allLists.add(new ArrayList());

And you want to remove one of these lists like this...

public void deleteList(int listNumber){
    allLists.remove(listNumber);
}

So that if you started with 3 lists in allLists and then removed 1 of them, you could ask allLists.size() and it would tell you that there are only 2 lists left?

If its neither of these, you'll really need to explain your question better so that we can help you.


From List interface:

Removes from this list all of its elements that are contained in the specified collection (optional operation).

boolean removeAll(Collection<?> c);

Need Your Help

ios http POST (Data and Image): Image not getting posted

ios objective-c image cocoa-touch http-post

I used the following code to PUSH an image and data into a server. The data is being sent but the image is not received in the server. Can someone spot me if there is an error in my below code whic...