-1

ArrayListJavaでを使用するのは初めてです。いくつかのリストがあり、リストとその要素を削除するメソッドを作成したいと考えています。これが私がこれまでに持っているものです:

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

その後、出力を取得したい:

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

2 に答える 2

0

リスト インターフェイスから:

指定されたコレクションに含まれるすべての要素をこのリストから削除します (オプションの操作)。

boolean removeAll(Collection<?> c);
于 2012-04-13T00:04:05.013 に答える
0

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.

于 2012-04-13T03:02:52.637 に答える