5 Replies Latest reply: Nov 16, 2011 9:57 AM by 796440 RSS

    Sorting in List<Hash Map>

      Hi All ,
      I i have the data in below format:

      Name     Age     Skill     Company
      Vass     21     Java     Zylog
      Samy     24     PB     HP
      Lee     18     ADF     CTS
      Reng     16     Java     Info

      I converted this data into java collections List<Hash Map> like this.
      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.List;
      public class HashMapDemo {
          public static void main(String[] args) {
              // Create a hash map
              List<HashMap> list = new ArrayList<HashMap>();
              HashMap hm = new HashMap();
              hm.put("Name", new String("Vass"));
              hm.put("Age", new Integer(21));
              hm.put("Company", new String("Zylog"));
              hm.put("skill", new String("Java"));
              HashMap hm1 = new HashMap();
              hm1.put("Name", new String("Samy"));
              hm1.put("Age", new Integer(24));
              hm1.put("Company", new String("HP"));
              hm1.put("skill", new String("PB"));
              HashMap hm2 = new HashMap();
              hm2.put("Name", new String("Lee"));
              hm2.put("Age", new Integer(18));
              hm2.put("Company", new String("CTS"));
              hm2.put("skill", new String("ADF"));
              HashMap hm3 = new HashMap();
              hm3.put("Name", new String("Reng"));
              hm3.put("Age", new Integer(16));
              hm3.put("Company", new String("Info"));
              hm3.put("skill", new String("Java"));
              Iterator i = list.iterator();
              while (i.hasNext()) {
      As per data (table format) i want to sort the data in Column level
      how can i to achieve ?.

      List<HashMap> is type of collection is help to me?

      Any idea?

      Vass Lee