In python, you can use a very simple if statement to see if what the user has entered (or just a variable) is in a list:
myList = ["x", "y", "z"]
myVar = "x"
if myVar in x:
print("your variable is in the list.")
How would I be able to do this in Java?
Answer
If your array type is a reference type, you can convert it to a List
with Arrays.asList(T...)
and check if it contains the element
if (Arrays.asList(array).contains("whatever"))
// do your thing
No comments:
Post a Comment