CharSetUtils: squeeze(String str, String set)
/*
Keep B and o = BoB
Squeeze B and o = Borisbbbecker
*/
import org.apache.commons.lang.CharSetUtils;
public class CharSetUtilsTrial {
public static void main(String[] args) {
// Keeps only the characters specified
System.out.println("Keep B and o = " + CharSetUtils.keep("BorisBecker", "Bo")); // BoB
// Removes specified character repetitions
System.out.println("Squeeze B and o = " + CharSetUtils.squeeze("BBoooorisbbbecker", "Bo")); // Borisbbbecker
}
}
Apache-Common-Lang.zip( 248 k)Related examples in the same category