java - unceraintity with arrayList storing -
public void openfile(){ try { l = new formatter("try.txt"); system.out.println("opened file"); } catch (exception e){ system.out.println("did not open file"); } } public void addrecord(){ l.format("%s", namefield.gettext()); system.out.println("added name" + " " + namefield.gettext()); } public void onclose(){ l.close(); } /* trying store user data, have gui , anytime click sign want store namefield in array list, possible anytime close , reopen program , else puts in name adds array list instead of overriding earlier person put in? example in gui type in mike name, close , reopen , put in john name, add mike , john or john? , how make them co-exist? thank
it reads file, everytime close program , run again replaces whatever on first line.
with list
(of arraylist
1 implementation) can use add
method. example if had list contains single object string "mike", , execute nameslist.add("john")
(where nameslist
list<string>
) list contain 2 elements: "john" , "mike".
however, mention persisting data between program executions. default lists purely in memory data storage, , cleared each time close , reopen program. store them need form of data persistence. on heavy end full database, small project simple requirements can use sqlite - or text file.
Comments
Post a Comment