Monday, 16 December 2013

count occurrences of character in string in java



String s = "...";
int counter = 0;

 for( int i=0; i<s.length(); i++ )
{

if( s.charAt(i) == '@' )
{
counter++;
 }

 }

No comments:

Post a Comment