i wrote a function that take a string text and can access vector v that contains character. it loops on the text[i]. if found any char that is in v, then it should take text[i] and put it in the v2(a new vector) with the same index found in v? and out of bound exception is printed to me any help?
public void encode( StringBuffer text) // need test
{
int temp,temp3;
boolean t;
String temp2;
int j=0;
int sizeoftext=text.length()-1;
do
{
for(int i=v.size()-1;i>-1;--i) // loop on text
{
temp=(v.elementAt(i)).length();// length of the longest word in dictionary
temp2=text.substring(j, j+temp); //string with the same length of temp
if((v.elementAt(i).equals(temp2)))// check if they r equal
{
HERE IS THE PROBLEM >> v2.add(i,temp2); // if yes add it to v2
temp3=temp+1;// increase size to take the nxt char
v.addElement(text.substring(j,temp3)); //add it to the dictionay
// v2.trimToSize();
// v.trimToSize();
}
}
temp3=temp=0;
++j;
--sizeoftext;
}while(sizeoftext>-1);
}