twitter - Java: First item of Array do not display correctly -


i need compare words tweets , count how many times appear on text. used 2 cycle compare arraylist words , arraylist tweets first word of arraylist words don't display correctly , don't want count. output image supposed champions word count twice

my code is:

read txt words , save on arraylist

public arraylist <string> fread(string dir) throws filenotfoundexception, ioexception {     scanner s = new scanner(new file(dir));     arraylist<string> list = new arraylist<string>();     while (s.hasnext()){         list.add(s.next().tolowercase());     }     s.close(); return list; } 

get tweets , save them on arraylist

public arraylist<string> showtimeline() throws twitterexception {     list<status> statuses = twitter.gethometimeline(new paging (1,200));     arraylist<string> alltweets=new arraylist<string>();     (status status : statuses) {         alltweets.add(status.gettext().replaceall("https[^\\s]+","").tolowercase());     }             return alltweets; } 

compare 2 arrays:

public arraylist<string> result(arraylist<string>tweets, arraylist<string> palavras){          (int = 0; <palavras.size() ; i++) {             int count = 0;              (int j = 0; j <tweets.size() ; j++) {             if (tweets.get(j).contains(palavras.get(i))){                 count++;             }         }         numero.add(count);         result.add(palavras.get(i));                 }       return result; } 

and print

for (int = 0; <result.size() ; i++) {         system.out.printf("%40s",result.get(i)+"        "+numero.get(i)+"\n");      } 

static arraylist:

     static arraylist<integer> numero = new arraylist<integer>();      static arraylist<string> result = new arraylist<string>(); 

thanks ! :)

in method

public arraylist<string> result(arraylist<string>tweets, arraylist<string> palavras){      (int = 0; <palavras.size() ; i++) {         int count = 0;          (int j = 0; j <tweets.size() ; j++) {         if (tweets.get(j).contains(palavras.get(i))){             count++;         }     }     numero.add(count);     result.add(palavras.get(i));             }   return result; 

}

your if-statement finds single result , ends. can fix so

public static arraylist<string> result(arraylist<string>tweets, arraylist<string> palavras){     (int = 0; <palavras.size() ; i++) {         int count = 0;         (int j = 0; j <tweets.size() ; j++) {             boolean isdone = false; //new             int tweetchariter = 1; //new             while (!isdone){ //new                 if (tweets.get(j).substring(tweetchariter).contains(palavras.get(i))){ //altered                     tweetchariter += tweets.get(j).substring(tweetchariter).indexof(palavras.get(i)) +1; //altered                     count++;                 } else { //new                     isdone = true; //new                 }             }         }         numero.add(count);         result.add(palavras.get(i));     }     return result; } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo