Skip to content

Instantly share code, notes, and snippets.

@eyeahs
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyeahs/b9e988460f44f85c5e87 to your computer and use it in GitHub Desktop.
Save eyeahs/b9e988460f44f85c5e87 to your computer and use it in GitHub Desktop.
Collection Gist
// Delete items while iterate
Iterator<Long> iterator = anyArrayList.iterator();
while (iterator.hasNext()) {
long value = iterator.next();
if (/** condition **/) {
iterator.remove();
}
}
// Find duplicates
boolean duplicates(final int[] zipcodelist)
{
Set<Integer> lump = new HashSet<Integer>();
for (int i : zipcodelist) {
if (lump.contains(i)) return true;
lump.add(i);
}
return false;
}
// Create Immutable
Integer[] values = { 1, 3, 7 };
List<Integer> list = Arrays.asList(values);
// Create Mutable
Integer[] values = { 1, 3, 7 };
List<Integer> list = new ArrayList<Integer>(Arrays.asList(values));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment