How to use list in DART language

In this article, i am going to explain list and method of list
  • 2672

List in DART language

A list is an indexable collection with a length. List are same as an array, the main advantage of list is that, you do not need to manage the size on your own. DART list like javaScript arrary literals. You can define list like as:

var list =[1,2,3,4,5];
  • You can add values in a list by add().
  • You can find out length of string by length().
  • You can access element direct from index no.
  • If you do not want to access list elements with Index , use the final.
for(final x in list){
  • If you want to apply function on each list elements, then use forEach().

var list=[1,2,3];

 MethElement(element) => print(element);


  • If you want to clear a list use clear().

  • If you want to access the last element of list, then use last();
  • If you want to remove a element from last, then use removeLast().

Example of list

void main() {

 var list =[1,2,3,4,5];

 var list2 = [8,9];

 print("Before adding list element is ${list}");


 print("After adding list element is ${list}");

 print("Lengthy of list is : ${list.length}");

 var list1=[1,2];

 for(final a in list1){

   print("WithOut Index access list element:${a}");



 MethElement(element) => print(element);

 print("Element through method");


 print("Acess list last elements: ${list.last()}");

 print("Remove last element from list :${list.removeLast()}");

 print("Remove all elements from list:${list.clear()}");

 print("Empty list:${list}");



Ask Your Question 
Got a programming related question? You may want to post your question here
© 2020 DotNetHeaven. All rights reserved.