How to sort ArrayList<LinkedHashMap<String,String>> by key?
<p>I am building a recipe searching app which takes recipe data from a website and displays it on the results page of the app (it's using JSON). I looked at tutorials on the web and found that a HashMap within an ArrayList was common for this sort of feature and I used a LinkedHashMap instead as I was interested in the insertion order.</p>

<p>The results of the information display fine on the recipe page. As my recipe page can have over 20+ recipes (depending on the search terms used), I want to give the user the option to resort the results list with the click of a button. </p>

<p><a href="https://i.stack.imgur.com/fAKI9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fAKI9.png" alt="enter image description here"></a></p>

<p>Here is a fragment of how I am populating my arraylist.</p>

<pre><code>static ArrayList&lt;LinkedHashMap&lt;String,String&gt;&gt; pairs = new ArrayList&lt;LinkedHashMap&lt;String,String&gt;&gt;();  
LinkedHashMap&lt;String, String&gt; map;

for (i=0; i&lt;matches.length(); i++){
map = new LinkedHashMap&lt;String, String&gt;();

map.put("id", id);
map.put("name", name);
map.put("rating", rating);
map.put("source", source);
pairs.add(map);
}
</code></pre>

<p>Below is an example of my arraylist (printed out)</p>

<pre><code>{id=1518539, name=Slow Cooker Mac and Cheese, rating=4, source=Merlot Mommy}
{id=1522143, name=Crock Pot Chicken Stroganoff, rating=4, source=Diethood}
{id=1506448, name=Slow Cooker Lemon-Garlic Chicken, rating=4, source=Magic Skillet}
{id=1520809, name=Chicken Tortilla Soup, rating=4, source=How does your garden grow}
</code></pre>

<p>Here is my actionbar <code>onOptionsItemSelected</code> method</p>

<pre><code>@Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.a_z:
                //sort recipe name alphabetically
            case R.id.z_a:
                //sort recipe name reverse alphabetically

            case R.id.by_rating:
                //sort rating by highest values

            default:
                return super.onOptionsItemSelected(item);
        }

    }
</code></pre>

<p>So, how do I go about sorting this list, let's say alphabetically as an example.</p>