Skip to content

Instantly share code, notes, and snippets.

@doyonghoon
Last active November 2, 2017 23:06
Show Gist options
  • Save doyonghoon/ec45af494d64ec7ed968fb13643d3124 to your computer and use it in GitHub Desktop.
Save doyonghoon/ec45af494d64ec7ed968fb13643d3124 to your computer and use it in GitHub Desktop.
removeAll
private static void removeAll(Collection<Integer>... collections) {
for (Collection<Integer> c : collections) {
for (int i = 0; i < c.size(); i++) {
Collection<Integer> tmp = copyCollection(c);
if (tmp != null) {
long timeTaken = System.nanoTime();
for (int j = 0; j <= i; j++) {
tmp.remove(j);
}
timeTaken = timeTaken - System.nanoTime();
}
}
}
}
private static Collection<Integer> copyCollection(Collection<Integer> c) {
Collection<Integer> tmp = null;
if (c instanceof ArrayList) {
tmp = new ArrayList<>(c);
} else if (c instanceof LinkedList) {
tmp = new LinkedList<>(c);
} else if (c instanceof HashSet) {
tmp = new HashSet<>();
}
return tmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment