Skip to content

Instantly share code, notes, and snippets.

@lohic
Last active August 29, 2015 14:02
Show Gist options
  • Save lohic/d6b618578dde9272a8c7 to your computer and use it in GitHub Desktop.
Save lohic/d6b618578dde9272a8c7 to your computer and use it in GitHub Desktop.
in_array for processing
import java.util.Arrays;
void setup() {
String[] tableau = {
"test", "youpi", "apple"
};
println(in_array("rien", tableau));
}
/***
* Teste si un élément est contenu dans un tableau
* @param needle : l'élément à rechercher
* @param haystack : la tableau
* @return true si présent, sinon false
*/
public static boolean in_array(Object needle, Object[] haystack) {
return (Arrays.binarySearch(haystack, needle) >= 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment