0

I have an ArrayList of HashMap objects as result of parsing an XML file. I would like to create an ArrayList of values for a certain key for display in a ListView. Here is what I have so far:

    // Initialize the guideList ArrayList
    ArrayList<String> guideList = new ArrayList<String>();
    HashMap<String,Object> dict = null;

    // Get the data - returns an ArrayList
    Object obj = plist.getConfigurationObject("array");

    // make sure an ArrayList was returned
    if (obj instanceof ArrayList) {

        // initialize Iterator
        Iterator itr = ((ArrayList) obj).iterator();
        int i = 0;

        // Loop through and create guideList ArrayList
        while (itr.hasNext()) {
            itr.next();
            dict = ((ArrayList<HashMap>) obj).get(i++);
            Object guideNo = dict.get("GUIDE_NO");
            guideList.add( "Guide "+guideNo.toString() );
        }
    }

This code does work, but is it the most efficient?

gunr2171
  • 16,104
  • 25
  • 61
  • 88
wyoskibum
  • 1,869
  • 2
  • 23
  • 43
  • Are you having some trouble with it this way? Or is it working properly but you are just wondering if there is a better way to do it? – FoamyGuy Jun 15 '12 at 00:59
  • Duplicate of http://stackoverflow.com/questions/1026723/how-to-convert-a-map-to-list-in-java? – Christian Garbin Jun 15 '12 at 01:04
  • Thanks for the replies. This code does work, I'm concerned about performance on larger data sets. – wyoskibum Jun 15 '12 at 10:17
  • 1
    This is not a duplicate of the above question which is about retrieving a list values and keys from a Map. While I'm looking for the most efficient way to iterate through an Array of Maps. – wyoskibum Jun 15 '12 at 10:54

0 Answers0