June 10th, 2003, 08:37 AM
Finding elements in an array
I'm trying to find if a value exists as an element of an array. In PHP I'd use in_array(v,a) but I don't know what to use in JSP. Can anybody help please?
June 10th, 2003, 09:50 AM
You can use Arrays.binarySearch(), but the array MUST be sorted beforehand or it won't work. Sorting the array just to search it probably wouldn't be very efficient. If you don't want to sort it you will have to roll-your-own search method.
Depending on your needs, you may want to look into using some sort of Collection instead of an array. ArrayList, for example, has an indexOf(Object) method that will return to you the index of the specified object. HashMap has a method called containsValue(Object) that returns a boolean. Either of these would likely work for you.