Last active
November 2, 2017 23:06
-
-
Save doyonghoon/ec45af494d64ec7ed968fb13643d3124 to your computer and use it in GitHub Desktop.
removeAll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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