SQL IN condition in Java

Let's take a look about SQL in features

SQL WHERE IN returns values that match values in a list


So I would use a collection, which implements from Collection<E> and had contains method, make the if statement simpler.

contains(Object o) Returns true if this set contains the specified element.

contains effect is very similar to SQL in.


1.add your multiple conditions in the collection, which implements from Collection<E>

Set<String> dict = new HashSet<String>();
dict.add("Finalized");
dict.add("Ready");
dict.add("Checkout");
dict.add("Confirmed");
dict.add("Book");
dict.add("Started");
dict.add("Inital");
dict.add("Close");

2.using contains to check input value whether exist in the collection.

if (dict.contains(pouch.getStatus()))
{
     // do your logic
}

You can use the method matches which is available in String class,

if(pouch.getStatus().matches("Finalized|Ready|Checkout|Confirmed|Book|Started|Inital|Close")){
   //your implementation goes here
}