java - Finding specific value inside an Array (not List) -


i learning arrays , did quiet few experiments, of them went well, i'm stuck. want archive is, find if specific value (string, int or whatever), exists inside array , if does, use value i.e code below count how many times value present inside array:

package arraysonly; import java.util.*; public class arraycontainsstring {     public static void main(string[]args)         {                    scanner sc = new scanner(system.in);             int arraysize = 0;             int wordcount = 0;              system.out.println("how many words gonna type?: ");             arraysize = sc.nextint();              string[] words = new string[arraysize];     // simple array, size of decided user-input              for(int count = 0; count < arraysize; count++)             {                 system.out.println("enter " + (count+1) + ": ");                 words[count] = sc.next();             }              //basically part i'm having troubles              if(in_array("ubt", $words)             {                  wordcount++;             }         } } 

i know this,

if(arrays.aslist(words).contains("ubt")); 

which converts array list / arraylist or whatever, want treat array if possible.

you can iterate on array

for (string str : array){   if(str.equals("ubt")){        wordcount++;  }     } 

edit:

it's equivalent normal loop

for(int i=0; i<array.length; i++) {     if(array[i].equals("ubt")){            wordcount++;      }  }  

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -