Java tutorial
//package com.java2s; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { public static Set minus(Set oriSet, Set tarSet) { if (oriSet == null || oriSet.size() == 0) return oriSet; if (tarSet == null || tarSet.size() == 0) return oriSet; Iterator oriItor = oriSet.iterator(); Set minusSet = new HashSet(); while (oriItor.hasNext()) { Object oriObj = oriItor.next(); Iterator tarItor = tarSet.iterator(); boolean isExist = false; while (tarItor.hasNext()) { Object tarObj = tarItor.next(); if (tarObj.equals(oriObj)) { isExist = true; break; } } if (!isExist) { minusSet.add(oriObj); } } return minusSet; } }