I am developing and android application using Java. I need my application to get the phone prefix from Country code.
Say for example, if the country code is US, it should return back prefix as "+1" in case of code IN, it should return back "+91", so on and so forth.
This can be achieved by having a function with if-else block as follows:
String getPrefix(String iso){
String prefix = "";
if(iso.equalsIgnoreCase("AD")) prefix = "376";
else if(iso.equalsIgnoreCase("AE")) prefix = "971";
else if(iso.equalsIgnoreCase("AF")) prefix = "93";
else if(iso.equalsIgnoreCase("AG")) prefix = "268";
else if(iso.equalsIgnoreCase("AI")) prefix = "264";
....
....
return prefix;
}
Or we can have a big vector object with all the key value pair, and the prefix can be retrieved by calling the get method on that object.
I need this function to be called once for the program life cycle. Please suggest me the best logic to implement this.
Regards.