arraylist search for value o(1) without hashset code example
Example 1: Fast Lookup of Java
Set<String> animals = new HashSet<String>(
Arrays.asList("cat", "dog", "squirrel", "raccoon"));
if (animals.contains("dog")) {
System.out.println("Yep, dog's here!");
}
if (!animals.contains("aardvark")) {
System.out.println("Ah, aardvark's missing!");
}
Example 2: java check if key exists in list
if (lista.contains(conta1)) {
System.out.println("Account found");
} else {
System.out.println("Account not found");
}