Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 194577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:36:26+00:00 2026-05-11T16:36:26+00:00

I want to have a List or Array of some sort, storing this information

  • 0

I want to have a List or Array of some sort, storing this information about each country:

  • 2 letter code
  • Country name such as Brazil
  • Continent/region of the world such as Eastern Europe, North America, etc.

I will classify each country into the region/continent manually (but if there exists a way to do this automatically, do let me know). This question is about how to store and access the countries. For example, I want to be able to retrieve all the countries in North America.

I don’t want to use local text files or such because this project will be converted to javascript using Google Web Toolkit. But storing in an Enum or another resource file of some sort, keeping it separate from the rest of the code, is what I’m really after.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:36:26+00:00Added an answer on May 11, 2026 at 4:36 pm

    There is 246 countries in ISO 3166, you might get a relay big enum on back of this. I prefer to use XML file with list of countries, you can download one from http://www.iso.org/ and load them (e.g. when app is starting).
    Than, as you need them in GWT load them in back as RPC call, but remember to cache those (some kind of lazy loading) so you wont finish with loading them each time.
    I think this would be anyway better than holding them in code, as you will finish with loading full list each time module is accessed, even if user will not need to use this list.

    So you need something which will hold country:

    public class Country
    {
        private final String name;
        private final String code;
    
        public Country(String name, String code)
        {
            this.name = name;
            this.code = code;
        }
    
        public String getName()
        {
            return name;
        }
    
        public String getCode()
        {
            return code;
        }
    
        public boolean equals(Object obj)
        {
            if (this == obj)
            {
                return true;
            }
            if (obj == null || getClass() != obj.getClass())
            {
                return false;
            }
    
            Country country = (Country) obj;
    
            return code.equals(country.code);
        }
    
        public int hashCode()
        {
            return code.hashCode();
        }
    }
    

    For GWT this class would need to implement IsSerializable.
    And you can load those, on server side using:

    import java.util.ArrayList;
    import java.util.List;
    import java.io.InputStream;
    
    import org.dom4j.Attribute;
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.Element;
    import org.dom4j.io.SAXReader;
    
    public class CountriesService
    {
        private static final String EL_COUNTRY = "ISO_3166-1_Entry";
        private static final String EL_COUNTRY_NAME = "ISO_3166-1_Country_name";
        private static final String EL_COUNTRY_CODE = "ISO_3166-1_Alpha-2_Code_element";
        private List<Country> countries = new ArrayList<Country>();
    
        public CountriesService(InputStream countriesList)
        {
            parseCountriesList(countriesList);
        }
    
        public List<Country> getCountries()
        {
            return countries;
        }
    
        private void parseCountriesList(InputStream countriesList)
        {
            countries.clear();
            try
            {
                Document document = parse(countriesList);
                Element root = document.getRootElement();
                //noinspection unchecked
                Iterator<Element> i = root.elementIterator(EL_COUNTRY);
                while (i.hasNext())
                {
                    Element countryElement = i.next();
                    Element countryName = countryElement.element(EL_COUNTRY_NAME);
                    Element countryCode = countryElement.element(EL_COUNTRY_CODE);
    
                    String countryname = countryName.getText();
                    countries.add(new Country(countryname, countryCode.getText()));
                }
            }
            catch (DocumentException e)
            {
                log.error(e, "Cannot read countries list");
            }
            catch (IOException e)
            {
                log.error(e, "Cannot read countries list");
            }
        }
    
        public static Document parse(InputStream inputStream) throws DocumentException
        {
            SAXReader reader = new SAXReader();
            return reader.read(inputStream);
        }
    }
    

    Of course, if you need to find country by ISO 2 letter code you might wont to change List to Map probably.
    If, as you mentioned, you need separate countries by continent, you might extend XML from ISO 3166 and add your own elements. Just check their (ISO website) license.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array containing a list of files. I want to sort it
I have some problem to compare values from different array list From this values,
I have an array which I want to sort using some custom logic. new
I have a collection (or list or array list) in which I want to
I have List I want to sort Desc by Priority, which is int and
I have List of particular class. I want to save this List at a
Hi all I have list of type string with some items. i want to
Hi I have an array list which has some numbers in it like {23,16,45,26,2,5,9}
I have an unsorted list but I want to sort in a custom way
I have an array, with some names (String) in it. 1.) I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.