public static String removeConsecutiveDuplicates(String s){
  String previous="??";
  StringBuffer result=new StringBuffer();
  for (int i=0; i < s.length(); i++) {
    String c=s.charAt(i) + "";
    if (!previous.equalsIgnoreCase(c)) {
      result.append(c);
    }
    previous=c;
  }
  return result.toString();
}

public static String removeConsecutiveDuplicates ( String s ) { String previous = "??" ; StringBuffer result = new StringBuffer ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { String c = s . charAt ( i ) + "" ; if ( ! previous . equalsIgnoreCase ( c ) ) { result . append ( c ) ; } previous = c ; } return result . toString ( ) ; }
replaces consecutive instances of characters with single instances . case - insensitive .
