public static String retainAllChars(String str,String retainChars){
  int pos=indexOfChars(str,retainChars);
  if (pos == -1) {
    return "";
  }
  StringBuilder buf=new StringBuilder();
  do {
    buf.append(str.charAt(pos));
    pos=indexOfChars(str,retainChars,pos + 1);
  }
 while (pos != -1);
  return buf.toString();
}

public static String retainAllChars ( String str , String retainChars ) { int pos = indexOfChars ( str , retainChars ) ; if ( pos == - 1 ) { return "" ; } StringBuilder buf = new StringBuilder ( ) ; do { buf . append ( str . charAt ( pos ) ) ; pos = indexOfChars ( str , retainChars , pos + 1 ) ; } while ( pos != - 1 ) ; return buf . toString ( ) ; }
removes all characters from ' str ' that are not in ' retainchars ' . example : retainallchars ( " hello , world ! " , " lo " ) returns " llool "
