Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; public class Main { /** * <p>Generate reverse result</p> * @param allResult all result * @param partResult part result * @return reverse result */ public static <T extends Object> List<T> getReverseResult(Set<T> allResult, Set<T> partResult) { List<T> resultList = new ArrayList<T>(); Map<T, T> map = new HashMap<T, T>(); if (partResult != null) { for (T obj : partResult) { map.put(obj, obj); } } if (allResult != null) { Iterator<T> itor = allResult.iterator(); while (itor.hasNext()) { T obj = itor.next(); if (map.containsKey(obj)) { itor.remove(); } else { resultList.add(obj); } } } return resultList; } }