Playing with HTMLTopWhat makes Strings unique among Java Object types?Some useful String methods

Some useful String methods

The demo program StringDemo

Demo 2. A case-insensitive word counter/finder differs from the above code only by the added two lines in the following.
  private int substringCounter( String text, String word)
  {
        int count = 0;
        int pos;
        
        text = text.toLowerCase();
        word = word.toLowerCase();
        
        pos = text.indexOf(word,0);
        
        while ( pos >= 0 )
        {
            count++;
            pos = text.indexOf(word,pos+word.length());
        
        }
        return count;
  }
    

Note that the assignment statements to text and word are required. String methods do not manipulate the given string. They make a brand new one.


Playing with HTMLTopWhat makes Strings unique among Java Object types?Some useful String methods