用 Java 实现以下 Python 代码的最简单/有效的方法是什么?
if "foo" in ["foo", "bar"]:
print "found."
最佳答案
如果您的数据位于数组中,请使用此
String[] strings = {"foo","bar"};
for (String s : strings) {
if (s.equals("foo")) {
System.out.println("found");
break;
}
}
关于java - Java 中是否有 "in"Python 关键字等效项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14772390/