[SOLVED] Searching a string in a vector
I have a vector say vector v = [(1), (2), (1 2)]
Now if I try to find the index of a string s={"1"} in the vector v, I get the answer, ie, 0 in this case.
But I cannot find the index of a string such as string s={"1 2"}. I get -1 as answer although I shud be getting 2 in this case. The complete program is as shown below . Please suggest me a solution. Thankyou.
Code:
import java.io.*;
import java.util.*;
class test
{
public static void main(String args[])
{
Vector v1=new Vector();
v1.addElement("1");
v1.addElement("2");
v1.addElement("3");
v1.addElement("1 2");
v1.addElement("1 3");
v1.addElement("2 3");
String itemset="1 2 3";
String[] ss=itemset.split(" ");
int len=ss.length;
int i,j;
String str1;
String str2=new String();
String str3=new String();
if (len==1);
else{
for (i=1;i<=len;i++) {
StringTokenizer st=new StringTokenizer(itemset);
str1=new String();
for (j=1;j<i;j++) {
str1=str1.concat(st.nextToken());
str1=str1.concat(" ");
}
str2=st.nextToken();
for (j=i+1;j<=len;j++) {
str1=str1.concat(st.nextToken());
str1=str1.concat(" ");
}
int ind1=v1.indexOf(str1);
int ind2=v1.indexOf(str2);
System.out.println(str1);
System.out.println(ind1);
System.out.println(str2);
System.out.println(ind2);
}//end for
}//end else
}
}