Last active
August 29, 2015 14:02
-
-
Save lohic/d6b618578dde9272a8c7 to your computer and use it in GitHub Desktop.
in_array for processing
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
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