How to Append or Concatenate Strings in Dart?

In Dart concatenation of string can be done in four different ways:

  1. By using ‘+’ operator.
  2. By string interpolation.
  3. By directly writing string literals.
  4. By Strings.join() method.

By ‘ + ‘ Operator

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

Example: Using ‘+’ operator to concatenate strings in Dart.

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

// Main function
void main() {
    
  // Assigning values
  // to the variable
  String gfg1 = "Geeks";
  String gfg2 = "For";
    
  // Printing concated result
  // by the use of '+' operator
  print(gfg1 + gfg2 + gfg1);
}

chevron_right


 



Output:

GeeksForGeeks

By String Interpolation

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

Example: Using string interpolation to concatenate strings in Dart. 

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

// Main function
void main() {
    
  // Assigning values to the variable
  String gfg1 = "Geeks";
  String gfg2 = "For";
    
  // Printing concated result
  // by the use of string
  // interpolation without space
  print('$gfg1$gfg2$gfg1');
    
  // Printing concated result
  // by the use of
  // string interpolation
  // with space
  print('$gfg1 $gfg2 $gfg1');
}

chevron_right


 

Output:

GeeksForGeeks
Geeks For Geeks

By Directly Writing String Literals

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

Example: By directly writing string literals to concatenate strings in Dart. 



Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

// Main function
void main() { 
    
  // Printing concated
  // result without space
  print('Geeks''For''Geeks');
    
  // Printing concated
  // result with space
  print('Geeks ''For ''Geeks');
}

chevron_right


 

Output:

GeeksForGeeks
Geeks For Geeks

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) are inserted between each element of the list in the output string.

Example: Using list_name.join() concatenate strings in Dart. 

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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
  // concated string
  print(geek1);
    
  // Joining all the elements
  // of the list and converting
  // it to String
  String geek2 = gfg.join(" ");
    
  // Printing the
  // concated string
  print(geek2);
}

chevron_right


 

Output:

GeeksForGeeks
Geeks For Geeks



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.