it may be a nooby question, but I’ve never needed it before:
I have several strings and I want to compare them to given ones…
At first glance it would lead to a switch/case construction in what every available entry is checked.
Is there a more elegant way to swap those strings as key/value datas?
greets,
poeschlorn
Update: My bad. I misread this as case insensitive search.
Case sensitive is easy. Java does not yet support
Strings inswitchstatements. The easiest solution is:Or as a loop:
Of course, this is linear (O(n)) and doesn’t scale but is simple and is sufficient for the simplest of cases. A better solution is to use a hash-based lookup:
This is near-linear (O(1)) lookup and will scale much better with a large number of
Strings.