static String encodeEntities(String source){
  StringBuffer buffer=new StringBuffer();
  String encoded;
  for (int index=0; index < source.length(); index++) {
    char ch=source.charAt(index);
    if ((encoded=encodeEntity(ch)) != null) {
      buffer.append(encoded);
    }
 else {
      buffer.append(ch);
    }
  }
  return buffer.toString();
}

static String encodeEntities ( String source ) { StringBuffer buffer = new StringBuffer ( ) ; String encoded ; for ( int index = 0 ; index < source . length ( ) ; index ++ ) { char ch = source . charAt ( index ) ; if ( ( encoded = encodeEntity ( ch ) ) != null ) { buffer . append ( encoded ) ; } else { buffer . append ( ch ) ; } } return buffer . toString ( ) ; }
utility method for encoding html entities within query parameters .
