Skip to content

Instantly share code, notes, and snippets.

@yareally
Last active December 18, 2015 16:19
Show Gist options
  • Save yareally/5810767 to your computer and use it in GitHub Desktop.
Save yareally/5810767 to your computer and use it in GitHub Desktop.
int n = 0;
for (String s: array) {
if (s.length > 2 && mapping.containsKey(s)) n++;
}
String[] bigEnough = new String[n];
n = 0;
for (String s: array) {
if (s.length <= 2) continue;
bigEnough[n++] = map.get(s);
}
// same code as above, only in Scala instead of Java
val bigEnough = array.filter(_.length > 2).flatMap(mapping.get)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment