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*

8
  • values() creates and populates a new array? I don't remember hearing that before, but presumably you have a source? Commented Jul 22, 2009 at 20:27
  • 12
    Well it returns an array... and it can't protect you from mutating that array... and it wouldn't subsequent callers to be hampered by that. Other than that, look at the JRE sources :) Commented Jul 22, 2009 at 20:29
  • 2
    Oops, sorry - yes, just checked myself. Decompile an enum then :) It uses clone() which may be pretty quick, but not as quick as not having to do it at all... Commented Jul 22, 2009 at 20:32
  • 1
    Are there any guidelines as to what "size" enums benefit from the Map-based approach vs. the array/loop approach? (I'm not looking for hard/fast rules, just a general ballpark of when to think about doing one way vs. the other) Commented May 12, 2014 at 19:28
  • 1
    @cdeszaq: I suspect it could vary significantly between JVMs and situations. If it's something you're concerned may be significant in your app, I suggest you do performance tests. Sorry not to be able to be more helpful :( Commented May 12, 2014 at 19:37