Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 8
    Long way around it, but you can use a for loop: "for (String s : VALUES) if (s.equals("MYVALUE")) return true; Commented Jul 15, 2009 at 0:51
  • 3
    @camickr--I have a nearly identical situation with this one: stackoverflow.com/a/223929/12943 It just keeps getting votes yet was just a copy/paste from sun's documentation. I guess score is based on how much help you provided and not how much effort you put into it--and mostly how fast you post it! Maybe we've stumbled onto John Skeet's secret! Well good answer, +1 for you. Commented Apr 29, 2013 at 6:50
  • 3
    If you're using Apache Commons, then org.apache.commons.lang.ArrayUtils.contains() does this for you. Commented Nov 12, 2013 at 21:05
  • 52
    @camickr because people, like me, google a question, click on the SO result, see your answer, test it, it works, upvote the answer and then leave. Commented Jul 20, 2015 at 2:41
  • 3
    I really miss a simple indexOf and contains in java.util.Arrays - which would both contain straightforward loops. Yes, you can write those in 1 minute; but I still went over to StackOverflow expecting to find them somewhere in the JDK. Commented May 1, 2020 at 10:38