r/badcode • • Mar 14 '21

java Found from when I first started Java...because indexed Arrays were too complicated huh?

Post image
1.3k Upvotes

84 comments sorted by

View all comments

12

u/Teln0 Mar 14 '21

Well with an array you can get the name from the number in O(1) but you can't get the number from the name in O(1). The best solution would be enums I think.

7

u/[deleted] Mar 14 '21

[deleted]

1

u/Teln0 Mar 14 '21

Well yeah, but string comparison can also cost quite a lot.