「java」コレクション(ArrayList)のlist.remove()で要素を削除するコード

javaコード
package com.startnews.pp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListRemov {
public void delete(){
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(2);
list.add(3);
this.iteratorDelete(list.iterator(), 2);
this.outputList(list);
}

private void iteratorDelete(Iterator<Integer> it, int deleteObject){
while(it.hasNext()){
int i = it.next();
if(i==deleteObject){
it.remove();
}
}
}

private void outputList(List<Integer> list){
for (Integer i : list) {
System.out.println(i);
}
}

public static void main(String[] args) {
ListRemov t = new ListRemov();
t.delete();
}

}
実行結果
1
3

Java

Posted by arkgame