java - How to use ListIterator effectively? -


i have method following -:

public void apply(arraylist<string> tokenstream); 

in accept list of string tokens following - tokenstream = ("i good" , "i bad") , , want able convert these tokens in tokenstream list individual tokens , add them same list in manner after method execution on should have - tokenstream = ("i" , "am" ,"good" , "i" , "am" , "bad"), how can use listiterator solve problem? want able split individual strings in tokenstream , add them same stream object using listiterators set , remove methods, how do it?

this trying do

public void apply(tokenstream stream){          if (stream != null) {              arraylist<string> splittedtokens = new arraylist<>();              while (stream.hasnext()) {                  string token = stream.next();                  string[] splittokens = token.split("\\s+");                  (int = 0; < splittokens.length; ++i)                     splittedtokens.add(splittokens[i]);             }              // set stream hold new formed stream tokens             stream.set((string[]) splittedtokens.toarray());         }     } 

i trying remove whitespace tokens in token stream object internally uses array list store tokens , tokenstream class has set of methods complementing of listiterator class set , remove, how go implementing that?

for task best way seems to create temp list, iterate tokenstream splitting tokens , adding them temp list, clear tokenstream , addall temp


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -