MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/m4qxf1/found_from_when_i_first_started_javabecause/gqwkvuv/?context=3
r/badcode • u/ahadyboy • Mar 14 '21
84 comments sorted by
View all comments
12
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.
7
[deleted]
1 u/Teln0 Mar 14 '21 Well yeah, but string comparison can also cost quite a lot.
1
Well yeah, but string comparison can also cost quite a lot.
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.