How can I check if an element exists in a Set of items?

static final List<String> fruits = Arrays.asList("APPLE", "ORANGES", "GRAPES");

if (fruits.contains(fruitname))

If your list was much larger, a set would be more efficient.

static final Set<String> fruits = new HashSet<String>(
       Arrays.asList("APPLE", "ORANGES", "GRAPES", /*many more*/));

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)