Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /** * Answer a set containing all elements that are both in source and in query * Delete these elements from source Creation date: (13.10.2002 16:23:00) * * @return java.util.Set * @param source * java.util.Set * @param elements * java.util.Collection */ public static Set extractFrom(Set source, Collection query) { Set answer = new HashSet(); Iterator i = query.iterator(); while (i.hasNext()) { Object o = i.next(); if (source.remove(o)) { answer.add(o); } } return answer; } }