English 中文(简体)
Java 将国家代码甲型-2(IN)改为甲型3 (IND)
原标题:Java code to convert country codes alpha-2 (IN) to alpha 3 (IND)

Using Java, Is there a quick way to convert an alpha-2 country code (IN or GB) to the alpha-3 equivalent (IND or GBR)?

我可以拿到甲型-2代码:

String[] Code = java.util. Locale.getISOLanguages();

这不是一个问题,实际上,我的申请在alpha-2法典中是这样说的,但我需要产出alpha-3等值。

是否有类似的办法获得甲型-3代码?

任何建议?

最佳回答

这项工作:

    Locale locale = new Locale("en","IN");
    System.out.println("Country=" + locale.getISO3Country());

产出:

Country=IND
问题回答

是的,简单地创建地方,如果从当地获得:

String alpha3Country = new Locale("en", alpha2County).getISO3Country();

BTW:getISOLanguages(> 回归语言代码(下级),getISOCountries( 返还国代码(续)

由于你读到这些守则中,你可以硬写这些守则,而应制作一个研究表,以转换为ISO代码。

public static void main(String[] args) {
        // setup
        Locale[] availableLocales = Locale.getAvailableLocales();
        HashMap<String, String> map = new HashMap<String, String>();
        for ( Locale l : availableLocales ) {
            map.put( l.getCountry(), l.getISO3Country() );
        }
        // usage
        System.out.println( map.get( "IN" ) );
        System.out.println( map.get( "GB" ) );
    }

Gopi的回答工作。 BUT注意到,回归代码为ISO 3166国家代码,而不是ISO 4217货币代码。 这些差异略有不同,因此谨慎使用





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签