The length of list is five but I want a length of list 150 [closed]
static final ArrayList<HashMap<String,String>> arraylistobject = new ArrayList<HashMap<String,String>>();
private void populateList() {
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("pen","MONT Blanc");
temp.put("price", "200 rs");
arraylistobject.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("pen","Gucci");
temp1.put("price", "300 rs");
arraylistobject.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("pen","Parker");
temp2.put("price", "400 rs");
arraylistobject.add(temp2);
HashMap<String,String> temp3 = new HashMap<String,String>();
temp3.put("pen","Sailor");
temp3.put("price", "500 rs");
arraylistobject.add(temp3);
HashMap<String,String> temp4 = new HashMap<String,String>();
temp4.put("pen","Porsche Design");
temp4.put("price", "600 rs");
arraylistobject.add(temp4);
You can use a loop to create the HashMaps and add them to your List, but you still have to do something about those hard-coded String literals.
for(int i = 0; i < 150; i++) {
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("pen", "MONT Blanc");
temp.put("price", "200 rs");
arraylistobject.add(temp);
}
You could read the values that you put in the temp
map from a configuration file or a database to initialize the List, but that's a whole other issue.
You should also check out the Java Tutorials: Collections articles.
A List
is meant to grow, not have a pre-initialised size. So if you want 150 as the length, you should add 150 elements to the list. Otherwise, stick to arrays.
Pretty sure this is what you're looking for:
HashMap temp5 = new HashMap();
arraylistobject.add(temp5);
HashMap temp6 = new HashMap();
arraylistobject.add(temp6);
HashMap temp7 = new HashMap();
arraylistobject.add(temp7);
HashMap temp8 = new HashMap();
arraylistobject.add(temp8);
HashMap temp9 = new HashMap();
arraylistobject.add(temp9);
HashMap temp10 = new HashMap();
arraylistobject.add(temp10);
HashMap temp11 = new HashMap();
arraylistobject.add(temp11);
HashMap temp12 = new HashMap();
arraylistobject.add(temp12);
HashMap temp13 = new HashMap();
arraylistobject.add(temp13);
HashMap temp14 = new HashMap();
arraylistobject.add(temp14);
HashMap temp15 = new HashMap();
arraylistobject.add(temp15);
HashMap temp16 = new HashMap();
arraylistobject.add(temp16);
HashMap temp17 = new HashMap();
arraylistobject.add(temp17);
HashMap temp18 = new HashMap();
arraylistobject.add(temp18);
HashMap temp19 = new HashMap();
arraylistobject.add(temp19);
HashMap temp20 = new HashMap();
arraylistobject.add(temp20);
HashMap temp21 = new HashMap();
arraylistobject.add(temp21);
HashMap temp22 = new HashMap();
arraylistobject.add(temp22);
HashMap temp23 = new HashMap();
arraylistobject.add(temp23);
HashMap temp24 = new HashMap();
arraylistobject.add(temp24);
HashMap temp25 = new HashMap();
arraylistobject.add(temp25);
HashMap temp26 = new HashMap();
arraylistobject.add(temp26);
HashMap temp27 = new HashMap();
arraylistobject.add(temp27);
HashMap temp28 = new HashMap();
arraylistobject.add(temp28);
HashMap temp29 = new HashMap();
arraylistobject.add(temp29);
HashMap temp30 = new HashMap();
arraylistobject.add(temp30);
HashMap temp31 = new HashMap();
arraylistobject.add(temp31);
HashMap temp32 = new HashMap();
arraylistobject.add(temp32);
HashMap temp33 = new HashMap();
arraylistobject.add(temp33);
HashMap temp34 = new HashMap();
arraylistobject.add(temp34);
HashMap temp35 = new HashMap();
arraylistobject.add(temp35);
HashMap temp36 = new HashMap();
arraylistobject.add(temp36);
HashMap temp37 = new HashMap();
arraylistobject.add(temp37);
HashMap temp38 = new HashMap();
arraylistobject.add(temp38);
HashMap temp39 = new HashMap();
arraylistobject.add(temp39);
HashMap temp40 = new HashMap();
arraylistobject.add(temp40);
HashMap temp41 = new HashMap();
arraylistobject.add(temp41);
HashMap temp42 = new HashMap();
arraylistobject.add(temp42);
HashMap temp43 = new HashMap();
arraylistobject.add(temp43);
HashMap temp44 = new HashMap();
arraylistobject.add(temp44);
HashMap temp45 = new HashMap();
arraylistobject.add(temp45);
HashMap temp46 = new HashMap();
arraylistobject.add(temp46);
HashMap temp47 = new HashMap();
arraylistobject.add(temp47);
HashMap temp48 = new HashMap();
arraylistobject.add(temp48);
HashMap temp49 = new HashMap();
arraylistobject.add(temp49);
HashMap temp50 = new HashMap();
arraylistobject.add(temp50);
HashMap temp51 = new HashMap();
arraylistobject.add(temp51);
HashMap temp52 = new HashMap();
arraylistobject.add(temp52);
HashMap temp53 = new HashMap();
arraylistobject.add(temp53);
HashMap temp54 = new HashMap();
arraylistobject.add(temp54);
HashMap temp55 = new HashMap();
arraylistobject.add(temp55);
HashMap temp56 = new HashMap();
arraylistobject.add(temp56);
HashMap temp57 = new HashMap();
arraylistobject.add(temp57);
HashMap temp58 = new HashMap();
arraylistobject.add(temp58);
HashMap temp59 = new HashMap();
arraylistobject.add(temp59);
HashMap temp60 = new HashMap();
arraylistobject.add(temp60);
HashMap temp61 = new HashMap();
arraylistobject.add(temp61);
HashMap temp62 = new HashMap();
arraylistobject.add(temp62);
HashMap temp63 = new HashMap();
arraylistobject.add(temp63);
HashMap temp64 = new HashMap();
arraylistobject.add(temp64);
HashMap temp65 = new HashMap();
arraylistobject.add(temp65);
HashMap temp66 = new HashMap();
arraylistobject.add(temp66);
HashMap temp67 = new HashMap();
arraylistobject.add(temp67);
HashMap temp68 = new HashMap();
arraylistobject.add(temp68);
HashMap temp69 = new HashMap();
arraylistobject.add(temp69);
HashMap temp70 = new HashMap();
arraylistobject.add(temp70);
HashMap temp71 = new HashMap();
arraylistobject.add(temp71);
HashMap temp72 = new HashMap();
arraylistobject.add(temp72);
HashMap temp73 = new HashMap();
arraylistobject.add(temp73);
HashMap temp74 = new HashMap();
arraylistobject.add(temp74);
HashMap temp75 = new HashMap();
arraylistobject.add(temp75);
HashMap temp76 = new HashMap();
arraylistobject.add(temp76);
HashMap temp77 = new HashMap();
arraylistobject.add(temp77);
HashMap temp78 = new HashMap();
arraylistobject.add(temp78);
HashMap temp79 = new HashMap();
arraylistobject.add(temp79);
HashMap temp80 = new HashMap();
arraylistobject.add(temp80);
HashMap temp81 = new HashMap();
arraylistobject.add(temp81);
HashMap temp82 = new HashMap();
arraylistobject.add(temp82);
HashMap temp83 = new HashMap();
arraylistobject.add(temp83);
HashMap temp84 = new HashMap();
arraylistobject.add(temp84);
HashMap temp85 = new HashMap();
arraylistobject.add(temp85);
HashMap temp86 = new HashMap();
arraylistobject.add(temp86);
HashMap temp87 = new HashMap();
arraylistobject.add(temp87);
HashMap temp88 = new HashMap();
arraylistobject.add(temp88);
HashMap temp89 = new HashMap();
arraylistobject.add(temp89);
HashMap temp90 = new HashMap();
arraylistobject.add(temp90);
HashMap temp91 = new HashMap();
arraylistobject.add(temp91);
HashMap temp92 = new HashMap();
arraylistobject.add(temp92);
HashMap temp93 = new HashMap();
arraylistobject.add(temp93);
HashMap temp94 = new HashMap();
arraylistobject.add(temp94);
HashMap temp95 = new HashMap();
arraylistobject.add(temp95);
HashMap temp96 = new HashMap();
arraylistobject.add(temp96);
HashMap temp97 = new HashMap();
arraylistobject.add(temp97);
HashMap temp98 = new HashMap();
arraylistobject.add(temp98);
HashMap temp99 = new HashMap();
arraylistobject.add(temp99);
HashMap temp100 = new HashMap();
arraylistobject.add(temp100);
HashMap temp101 = new HashMap();
arraylistobject.add(temp101);
HashMap temp102 = new HashMap();
arraylistobject.add(temp102);
HashMap temp103 = new HashMap();
arraylistobject.add(temp103);
HashMap temp104 = new HashMap();
arraylistobject.add(temp104);
HashMap temp105 = new HashMap();
arraylistobject.add(temp105);
HashMap temp106 = new HashMap();
arraylistobject.add(temp106);
HashMap temp107 = new HashMap();
arraylistobject.add(temp107);
HashMap temp108 = new HashMap();
arraylistobject.add(temp108);
HashMap temp109 = new HashMap();
arraylistobject.add(temp109);
HashMap temp110 = new HashMap();
arraylistobject.add(temp110);
HashMap temp111 = new HashMap();
arraylistobject.add(temp111);
HashMap temp112 = new HashMap();
arraylistobject.add(temp112);
HashMap temp113 = new HashMap();
arraylistobject.add(temp113);
HashMap temp114 = new HashMap();
arraylistobject.add(temp114);
HashMap temp115 = new HashMap();
arraylistobject.add(temp115);
HashMap temp116 = new HashMap();
arraylistobject.add(temp116);
HashMap temp117 = new HashMap();
arraylistobject.add(temp117);
HashMap temp118 = new HashMap();
arraylistobject.add(temp118);
HashMap temp119 = new HashMap();
arraylistobject.add(temp119);
HashMap temp120 = new HashMap();
arraylistobject.add(temp120);
HashMap temp121 = new HashMap();
arraylistobject.add(temp121);
HashMap temp122 = new HashMap();
arraylistobject.add(temp122);
HashMap temp123 = new HashMap();
arraylistobject.add(temp123);
HashMap temp124 = new HashMap();
arraylistobject.add(temp124);
HashMap temp125 = new HashMap();
arraylistobject.add(temp125);
HashMap temp126 = new HashMap();
arraylistobject.add(temp126);
HashMap temp127 = new HashMap();
arraylistobject.add(temp127);
HashMap temp128 = new HashMap();
arraylistobject.add(temp128);
HashMap temp129 = new HashMap();
arraylistobject.add(temp129);
HashMap temp130 = new HashMap();
arraylistobject.add(temp130);
HashMap temp131 = new HashMap();
arraylistobject.add(temp131);
HashMap temp132 = new HashMap();
arraylistobject.add(temp132);
HashMap temp133 = new HashMap();
arraylistobject.add(temp133);
HashMap temp134 = new HashMap();
arraylistobject.add(temp134);
HashMap temp135 = new HashMap();
arraylistobject.add(temp135);
HashMap temp136 = new HashMap();
arraylistobject.add(temp136);
HashMap temp137 = new HashMap();
arraylistobject.add(temp137);
HashMap temp138 = new HashMap();
arraylistobject.add(temp138);
HashMap temp139 = new HashMap();
arraylistobject.add(temp139);
HashMap temp140 = new HashMap();
arraylistobject.add(temp140);
HashMap temp141 = new HashMap();
arraylistobject.add(temp141);
HashMap temp142 = new HashMap();
arraylistobject.add(temp142);
HashMap temp143 = new HashMap();
arraylistobject.add(temp143);
HashMap temp144 = new HashMap();
arraylistobject.add(temp144);
HashMap temp145 = new HashMap();
arraylistobject.add(temp145);
HashMap temp146 = new HashMap();
arraylistobject.add(temp146);
HashMap temp147 = new HashMap();
arraylistobject.add(temp147);
HashMap temp148 = new HashMap();
arraylistobject.add(temp148);
HashMap temp149 = new HashMap();
arraylistobject.add(temp149);
HashMap temp150 = new HashMap();
arraylistobject.add(temp150);
精彩评论