1

What is the most simple/efficient way of implementing the following Python code in Java?

if "foo" in ["foo", "bar"]:
    print "found."
Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98

1 Answers1

3

If you have your data in array use this

String[] strings = {"foo","bar"};
    for (String s : strings) {
        if (s.equals("foo")) {
            System.out.println("found");
            break;
        }
    }
MiSu
  • 29
  • 1
  • 2
  • This is not the best answer. For better ones, see [In Java, how can I test if an Array contains a certain value?](http://stackoverflow.com/q/1128723/1097104) – Juuso Ohtonen Feb 09 '13 at 08:44