hello I am beginner to work with java. I have following code, where I wanted to initialize the string array word[] dynamically consisting of size of total no. of tokens in all documents [] array. how should I do that?
String []result = {"Shipment of Gold damaged in fire","Delivery of silver arrived in silver truck","shipment of Gold arrived in Truck"};
String []documents = new String[result.length];
for (int k =0; k<result.length; ++k){
documents[k] = result[k].toLowerCase();
System.out.println("document["+k+"] :" + documents[k]);
}
/*step 2: Tokenize all documents and create vocabulary from it*/
int i=0;
String [] word = new String [30]; // how to do dynamic allocation here
int no_of_tokens=0;
for(String document:documents){
StringTokenizer st = new StringTokenizer(document," ");
System.out.print("tokens in document"+ i +":"+ st.countTokens()+"\n");
while(st.hasMoreTokens()) {
word[no_of_tokens]=st.nextToken();
System.out.print(word[no_of_tokens] + "\n");
no_of_tokens++;
}
i++;
}