So I have searched for different libraries and couldn't find them. Basically, I have to get a country name when a user entered a phone number. Like the output shows: +1 (United States) +92(Pakistan) + 93(Afghanistan)
public static void main(String[] args) throws NumberParseException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your phone no.:");
String phone = sc.next();
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try{
Phonenumber.PhoneNumber locale = phoneUtil.parse(phone, "");
System.out.println("Country code: " + locale.getCountryCode() );
}
catch(NumberParseException e){
System.err.println("NumberParseException was thrown: " + e.toString());
}