The Strings.join()
method is used to concatenate strings in Dart programming. In Dart, we can easily combine a list’s elements into a single string with the Strings.join()
method.
Syntax:
list_name.join('input_string(s)');
The input string(s) are added between each element of the list in the output string.
The code below concatenates elements in the list.
// Main functionvoid main() {// Creating List of stringsList<String> myList = ["Educative", "shot"];List<String> myList2 = ["Orange", "banana", "mango", "apple"];// Using String.join() to convert elements of the list// into a StringString edu1 = myList.join();// display the concatenated stringprint(edu1);// adding space between the itemsString edu2 = myList.join(" ");print(edu2);// adding comma ',' between the items in the listString fruits = myList2.join(', ');print(fruits);}