Java Regex 2 - Duplicate Words

  • + 0 comments

    Has anyone faced the problem that code does not print to stdout even though it does in local machine? here is my code

            try (Scanner aScanner = new Scanner(System.in)){
                int num = aScanner.nextInt();
                List<String> linesAfterDeduplication = new LinkedList<>();
                for (int i = 0; i <= num; i++) {
                    String line = aScanner.nextLine().trim();
                    Matcher matcher = pattern.matcher(line);
                    while (matcher.find()) {
                        line = line.replace(matcher.group(0), matcher.group(1));
                    }
                    linesAfterDeduplication.add(line);
                }
    
                for (String line : linesAfterDeduplication) {
                    System.out.println(line);
                }
            }