title: USING collections in Android
body: <h2>I was looking at this code while surfing through Stackoverflow</h2>
  
  <p><strong>CODE::</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
      // Declare Variables
      JSONObject jsonobject;
      JSONArray jsonarray;
      ListView listview;
      ListViewAdapter adapter;
      ProgressDialog mProgressDialog;
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; arraylist;
      static String NAME = "rank";
      static String TYPE = "country";
      static String DISTANCE = "distance";
      static String RATING = "rating";
      static String FLAG = "flag";
      static String PRICE= "price";
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // Get the view from listview_main.xml
          setContentView(R.layout.listview_main);
  
  
          // Locate the listview in listview_main.xml
          listview = (ListView) findViewById(R.id.listview);
  
          // Execute DownloadJSON AsyncTask
          new DownloadJSON().execute();
      }
  
      // DownloadJSON AsyncTask
      private class DownloadJSON extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              // Create a progressdialog
              mProgressDialog = new ProgressDialog(MainActivity.this);
              // Set progressdialog title
              //mProgressDialog.setTitle("Fetching the information");
              // Set progressdialog message
              mProgressDialog.setMessage("Loading...");
              mProgressDialog.setIndeterminate(false);
              // Show progressdialog
              mProgressDialog.show();
          }
  
          @Override
          protected Void doInBackground(Void... params) {
              // Create an array
              arraylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
              // Retrieve JSON Objects from the given URL address
              jsonobject = JSONfunctions.getJSONfromURL("--------------URL----------");
  
              try {
                  // Locate the array name in JSON
                  jsonarray = jsonobject.getJSONArray("ARRAY");
  
                  for (int i = 0; i &lt; jsonarray.length(); i++) {
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                      jsonobject = jsonarray.getJSONObject(i);
                      // Retrive JSON Objects
                      map.put(MainActivity.NAME, jsonobject.getString("collegeNAME"));
                      map.put(MainActivity.TYPE, jsonobject.getString("collegeTYPE"));
                      map.put(MainActivity.FLAG, jsonobject.getString("collegeIMAGE"));
                      map.put(MainActivity.DISTANCE, jsonobject.getString("collegeDISTANCE"));
                      map.put(MainActivity.RATING, jsonobject.getString("collegeRATING"));
                      map.put(MainActivity.PRICE, jsonobject.getString("collegePrice"));
  
                      // Set the JSON Objects into the array
                      arraylist.add(map);
                  }
              } catch (JSONException e) {
                  Log.e("Error", e.getMessage());
                  e.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void args) {
              // Pass the results into ListViewAdapter.java
              adapter = new ListViewAdapter(MainActivity.this, arraylist);
              // Set the adapter to the ListView
              listview.setAdapter(adapter);
              // Close the progressdialog
              mProgressDialog.dismiss();
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <ul>
  <li>My Question is Why we use collection in android ?</li>
  <li>What is the use ?</li>
  <li>Why a hashmap is added to ArrayList in the above code ?</li>
  <li>Can't we directly set views in android without collection,( I tried
  it dosent work when dealing with group of key,value pairs)</li>
  </ul>
  
  <p>.
  ~ I am a newbie so please go easy on with answers to my questions </p>