public static String encode(String source){
  StringBuffer dest=new StringBuffer();
  int sourceLen=source.length();
  for (int i=0; i < sourceLen; i++) {
    int runLength=1;
    final char currentChar=source.charAt(i);
    while (i + 1 < sourceLen && currentChar == source.charAt(i + 1)) {
      runLength++;
      i++;
    }
    dest.append(runLength);
    dest.append(currentChar);
  }
  return dest.toString();
}

public static String encode ( String source ) { StringBuffer dest = new StringBuffer ( ) ; int sourceLen = source . length ( ) ; for ( int i = 0 ; i < sourceLen ; i ++ ) { int runLength = 1 ; final char currentChar = source . charAt ( i ) ; while ( i + 1 < sourceLen && currentChar == source . charAt ( i + 1 ) ) { runLength ++ ; i ++ ; } dest . append ( runLength ) ; dest . append ( currentChar ) ; } return dest . toString ( ) ; }
returns encoded string . for example , converts " wwwwwwwwwwwwbwwwwwwwwwwwwbbb " to " 12w1b12w3b "
