Dart – Concatenate a String with itself Multiple Times

To concatenate a string with itself multiple times in Dart, use Multiplication Operator * and pass the string and the integer as operands to it.

Syntax

The syntax to concatenate a string str with itself n number of times is

</>
Copy
str * n

Example

In this example, we take a string 'apple' with concatenate this string with itself 4 times.

main.dart

</>
Copy
void main() {
  var str = 'banana';
  var result = str * 4;
  print('Original String : "$str"');
  print('Result String   : "$result"');
}

Output

Original String : "banana"
Result String   : "bananabananabananabanana"

Conclusion

In this Dart Tutorial, we learned how to concatenate a string with itself multiple number of times, with examples.