java - Adding Input to JTextArea to an ArrayList of ArrayLists -


my objective add text jtextarea arraylist of arraylists, such each line of text inputted saved arraylist, words of particular line saved elements within arraylist of line. have idea of how store each line of inputted text element within arraylist, not how have arraylist of arraylists. point me in right direction here? create 2d arraylist , thinking this:

arraylist[][] poem = new arraylist[][]; 

this thinking making arraylist containing each line element, have each of lines seperate arraylist containing respective words elements:

jtextarea txarea = new jtextarea(); string txt = txarea.gettext(); string [] arrayoflines = txt.split("\n"); arraylist<string> linesasal = new arraylist<string>(); for(string line: arrayoflines){   linesasal.add(line); } 

in sum, trying make 2d arraylist, each word inputted jtextarea added own cell within 2d arraylist.

your question doesn't have jtextarea-specific, answer won't (i'm assuming know how string jtextarea. hint: http://docs.oracle.com/javase/7/docs/api/javax/swing/jtextarea.html).

here's method transform string arraylist<arraylist<string>>:

public static list<list<string>> linestolinesandwords(string lines) {     list<list<string>> wordlists = new arraylist<>();     list<string> linelist = arrays.aslist(lines.split("\n"));     (string line : linelist) {         wordlists.add(arrays.aslist(line.trim().split(" ")));     }     return wordlists; } 

after seeing code, suggest learn java.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -