java - How to check if element of array contains any value or not -


this program saving string key , number of counts in string array. shown in condition clause (//condition) , unable check weather element of array contains value or not?

i know throws exception "java.lang.arrayindexoutofboundsexception" because cant allocate memory unspecified element. trying "nextstring.equals(arrays[i+1])" , doesn't work.

please specify condition can use.

public void mapexample() {      string text = "text text text";      string[] arrays = text.split(" ");      arrays.sort(arrays);      for(string array :arrays ){      system.out.println(array);      }          int count=0;          string thissring = "";          string nextstring="";          treemap<string,integer> mapper = new treemap<string , integer>();          for(int i=0;i<arrays.length;++i){              thissring = arrays[i];              count++;              nextstring = arrays[i+1];              if(!thissring.equals(nextstring)){                  mapper.put(thissring, count);              }                if(//condition){                  mapper.put(thissring, count);              }          }            set s = mapper.entryset();             iterator iter = s.iterator();             if(iter.hasnext()){             system.out.println(iter.next());             map.entry map = (map.entry) iter.next();             system.out.println( "key" + " " + map.getkey());             system.out.println("value" + " " + map.getvalue());         }      }      } 

your error earlier think,

for(int i=0;i<arrays.length - 1;++i){   // add "- 1" because,   thissring = arrays[i];   count++;   nextstring = arrays[i+1];             // exceed array length otherwise.   if(!thissring.equals(nextstring)){     mapper.put(thissring, count);   } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -