How to Check if an ArrayList Contain 2 values?
问题 is there any way to check if a collection contain a value or more with better performance than looping twice with contains? in other meaning something that would look like this person.contains("Joe" || "Jasha"); 回答1: The implementation of ArrayList.contains() loops through every element and does an equals() test, so calling .contains() twice is inefficient . You could write your own loop that check both at once using a compiled regex Pattern that looks for either name at the same time: