I'm writing a high throughput java application and need your help settle a debate. The application process strings at a very high frequency and I need to be able to check if the input contains a certain string.
The string is made up of two parts, part 1 and part 2. The two parts are concatenated with a space character.
var data = string1 + " " + string2;
To check if the input belong to my list, I have two approaches:
Approach 1:
Set<String> mylist;
...
void boolean isThere(String part1, String2 part2) {
return mylist.contains(part1 + " " + part2);
}
Approach 2:
Map<String,Set<String>> mylist;
void boolean isThere(String part1, String2 part2) {
var partA = mylist.get(part1);
if (partA != null) {
return partA.contains(part2);
}
return false;
}
The nature of the string parts are short-ish in nature, around 2 to 50 characters each.
Did some benchmarking with some mixed outcomes.