In an if statement in Java how can I check whether an object exists in a set of items. E.g. In this scenario i need to validate that the fruit will be an apple, ora
if
static final List 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 fruits = new HashSet( Arrays.asList("APPLE", "ORANGES", "GRAPES", /*many more*/));