General explaination:
Hi, I want to fill a vector of an array of strings tokenized that I pass in the arguments, then. I must fill an array that contain only once each word that appear in all strings, even if there are more than twice, because next step i must do, is to count the times each word is appearing.
That's why I use an string array inside vector, because I need method "split" and Class Vector hasn't any "splitter".
My problem:
Fail is in the condition if(!v.contains(vFrases.elementAt(i)[j])){ that is always true and it should be true when it contains twice a word
Maybe I missunderstood how to fill the array index in a vector
Maybe can I obtain same result I want, with a simple Vector? instead vector of arrays?
import java.util.Vector; public class Ejercicio { /** MAIN */ public static void main(String[] args) { if(args.length<1){ System.err.println("Usage: java Ejercicio <string> <string> "); return; } frecuenciasLexicas(args); } /** METHOD */ static void frecuenciasLexicas (String[] s){ Vector<String> v = new Vector<String>(); Vector<String[]> vFrases = new Vector<String[]>(); //I fill the vector of arrays with the strings I pass in the args "tokenized" with "split" for(int i=0; i<s.length ;i++) vFrases.addElement(s[i].split("\\s")); for(int i=0; i<vFrases.size() ;i++){ for(int j=0; j<vFrases.elementAt(i).length ;j++){ /** HERE is the PROBLEM, this condition is always false */ /** The vector "v" should contain only once each word that vector "vFrase" has inside, so if v doesn't contain the string, he add the string, but next time will not, because only must have it once each word*/ if(!v.contains(vFrases.elementAt(i)[j])){ v.addElement(vFrases.elementAt(i)[j]+"|"); } } for(int k=0; k<v.size();k++) System.out.println(v.elementAt(k)); } } }
ARG EXAMPLE:
"first string" "second string" "third string"
DESIRED OUTPUT (INSIDE V):
v.elementAt(0) -->first|
v.elementAt(1) -->string|
v.elementAt(2) -->second|
v.elementAt(3) -->third|
WHAT I GET:
v.elementAt(0) --> first|
v.elementAt(1) --> string|
v.elementAt(2) --> second|
v.elementAt(3) --> string|
v.elementAt(4) --> third|
v.elementAt(5) --> string|
Sorry for my english XD,
Thank you.