Duplicate Character Counter in Dart

Published on 04 October 2025 (Updated: 04 October 2025)

Welcome to the Duplicate Character Counter in Dart page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

//Issue 4974
void main(List<String> args){
  const String error_message = "Usage: please provide a string";
  if (args.isEmpty || args[0].isEmpty){
    print(error_message);
    return;
  } // end of empty check
  
  Map<String, int> frequency = {};
  bool duplicate_not_found = true;

  for (int i = 0; i < args[0].length; i ++){
    String char = args[0][i];
    if (RegExp(r'[a-zA-Z0-9]').hasMatch(char)) {
      frequency[char] = (frequency[char] ?? 0) + 1;
    }
  } // end of checking duplicate characters
  
  //either print all duplicate letters or set flag duplicate letters not found
  frequency.forEach((char, count){
    if (count > 1) {
      duplicate_not_found = false; // at least 1 duplicate letter is found
      print('$char: $count');
    }
  });
  // print if no duplicate characters
  if(duplicate_not_found == true){
      print("No duplicate characters");
  }
}

Duplicate Character Counter in Dart was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.