fork download
  1. import java.util.List;
  2.  
  3. class Ideone {
  4.  
  5. public static void main(String[] args) {
  6. List<String> input = List.of("abc", "yahoo", "opinion", "aaaaaabc");
  7.  
  8. for (String s: input) {
  9. System.out.println( s + " => " + s.replaceAll("(?:((.)\\2)|(.))", "$1$3$3") );
  10. }
  11. }
  12. }
  13.  
Success #stdin #stdout 0.14s 37324KB
stdin
Standard input is empty
stdout
abc => aabbcc
yahoo => yyaahhoo
opinion => ooppiinniioonn
aaaaaabc => aaaaaabbcc