Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static List<Integer> checkIdentical(List<Integer> list1, List<Integer> list2) { List<Integer> resultList = new ArrayList<Integer>(); Iterator<Integer> iterator1 = list1.iterator(); while (iterator1.hasNext()) { Integer next1 = iterator1.next(); Iterator<Integer> iterator2 = list2.iterator(); while (iterator2.hasNext()) { Integer next2 = iterator2.next(); if (next1.intValue() == next2.intValue()) { iterator1.remove(); iterator2.remove(); resultList.add(next1.intValue()); break; } } } return resultList; } }