I want to implement a function in java that gets string input and process it. Here is how i implement it using if else statement:
class Main {
static String string_process(String s_in) {
String s_out;
if(s_in.contains("USA")){
s_out = "english";
}
else if(s_in.contains("Germany")){
s_out = "dutch";
}
else if(s_in.contains("Brazil")){
s_out = "Portuguese";
}
else {
s_out = "Uknown";
}
return s_out;
}
public static void main(String[] args) {
String process = string_process("I am from USA!");
System.out.println("I understand "+process);
}
}
I'm wondering if i can implement it hashmap. Is there any benefit of doing so in terms of complexity?