java - save multidimensional arrayList -
i have multidimensional arraylist, composed of multiple rows of different length. save arraylist single tab-delimited file multiple columns, in each column corresponds specific row of arraylist. have tried come solution, thing think of save each arraylist row in separate files.
the arraylist called "array" , contains several rows of different length. here code:
try { printwriter output = new printwriter(new filewriter("try")); output.print(array.get(0)); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } }
in case, can save first row of arraylist single file. other solution have been thinking loop through rows, many separate files row numbers. however, single file multiple tab-delimited columns.
ecxuse me, old reply based on wrong interpretation of needs. made illustration code:
package com.test; import java.util.arraylist; import java.util.list; public class mulitarraylist { public static void main(string[] args) { list<string> innerarraylist1; list<string> innerarraylist2; list<string> innerarraylist3; list<list> outerarraylist; innerarraylist1 = new arraylist<string>(); innerarraylist2 = new arraylist<string>(); innerarraylist3 = new arraylist<string>(); //comic heros innerarraylist1.add("superman"); innerarraylist1.add("batman"); innerarraylist1.add("catwoman"); innerarraylist1.add("spiderman"); //historical persons innerarraylist2.add("stalin"); innerarraylist2.add("gandy"); innerarraylist2.add("lincoln"); innerarraylist2.add("churchill"); //fast nutrient innerarraylist3.add("mc donalds"); innerarraylist3.add("burger king"); innerarraylist3.add("subway"); innerarraylist3.add("kfc"); //fill outerarraylist outerarraylist = new arraylist<list>(); outerarraylist.add(innerarraylist1); outerarraylist.add(innerarraylist2); outerarraylist.add(innerarraylist3); //print for(list<string> innerlist : outerarraylist) { for(string s : innerlist) { system.out.print(s + "\t"); } system.out.println("\n"); } } }
the result is:
as can see, results printed tabs, space between them differentiate. can write same way file, not best way save data. hope help bit, greetings.
java arraylist tab-delimited-text
No comments:
Post a Comment