I was trying to solve a problem and I had this as a partial step to my solution. So if you were given a large boolean array fill with all true value except one false hiding within somewhere. Is there any efficient way to search for the index of that false rather than going through the whole array?
Hi thank you so much for taking your time to reply. I was aware of the usage of Arrays.asList but was reluctant because I thought it might allocate a brand new array or arraylist and needed to copy everything over again. Upon further reading, on more than one occasions, it appeared people are suggesting no new allocation were taking place other than just creating a specialized view or wrapper to the original array. Therefore minimum hit and memory usage for using Arrays.asList. If that is true then I think your solution is perfect. Thanks again!
However... I think it's very likely that the "indexOf" method works by "going through" the list, which is something you didn't seem to want in your original post. Or were you just looking for a solution which didn't require you yourself to write the code? If so, then Michael Dunn's solution is just fine.
(And yes, I do believe it's better to look for built-in solutions to ordinary problems like this one, rather than writing your own code. For one thing the built-in solutions already work, whereas code I write doesn't necessarily work the first time and needs to be tested and debugged. For another thing, the built-in solution has a chance of working better than the code I might write.)