How to Append or Concatenate Strings in Dart? (original) (raw)

Last Updated : 07 Apr, 2025

In Dart, the concatenation of strings can be done in four different ways:

1. Using the ' + ' Operator

In Dart, we can use the '+' operator to concatenate the strings.

**Example:

Dart `

// Main function void main() {

// Assigning values
// to the variable
String gfg1 = "Geeks";
String gfg2 = "For";

// Printing concatenated result
// by the use of '+' operator
print(gfg1 + gfg2 + gfg1);

}

`

**Output:

GeeksForGeeks

2. By String Interpolation

In Dart, we can use string interpolation to concatenate the strings.

**Example:

Dart `

// Main function void main() {

// Assigning values to the variable
String gfg1 = "Geeks";
String gfg2 = "For";

// Printing concatenated result
// by the use of string
// interpolation without space
print('$gfg1$gfg2$gfg1');

// Printing concatenated result
// by the use of
// string interpolation
// with space
print('$gfg1 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>g</mi><mi>f</mi><mi>g</mi><mn>2</mn></mrow><annotation encoding="application/x-tex">gfg2 </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord">2</span></span></span></span>gfg1');

}

`

**Output:

GeeksForGeeks
Geeks For Geeks

3. By Directly Writing String Literals

In Dart, we concatenate the strings by directly writing string literals and appending.

**Example:

Dart `

// Main function void main() {

// Printing concatenated
// result without space
print('Geeks''For''Geeks');

// Printing concatenated
// result with space
print('Geeks ''For ''Geeks');

}

`

**Output:

GeeksForGeeks
Geeks For Geeks

4. By List_name.join() Method

In Dart, we can also convert the elements of the list into one string.

list_name.join("input_string(s)");

This ****input_string(s)**is inserted between each element of the list in the output string.

**Example:

Dart `

// Main function void main() {

// Creating List of strings
List<String> gfg = ["Geeks", "For", "Geeks"];

// Joining all the elements
// of the list and
// converting it to String
String geek1 = gfg.join();

// Printing the
// concatenated string
print(geek1);

// Joining all the elements
// of the list and converting
// it to String
String geek2 = gfg.join(" ");

// Printing the
// concatenated string
print(geek2);

}

`

**Output:

GeeksForGeeks
Geeks For Geeks