{"id":3576,"date":"2022-05-19T05:41:16","date_gmt":"2022-05-19T05:41:16","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=3576"},"modified":"2022-05-19T05:41:16","modified_gmt":"2022-05-19T05:41:16","slug":"dart-lists","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/05\/19\/dart-lists\/","title":{"rendered":"Dart Lists"},"content":{"rendered":"\n<p>Dart List is similar to an array, which is the ordered collection of the objects. The array is the most popular and commonly used collection in any other programming language. The Dart list looks like the JavaScript array literals. The syntax of declaring the list is given below.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var list1 = &#91;10, 15, 20,25,25]  <\/code><\/pre>\n\n\n\n<p>The Dart list is defined by storing all elements inside the square bracket ([]) and separated by commas (,).<\/p>\n\n\n\n<p>Let&#8217;s understand the graphical representation of the list &#8211;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.javatpoint.com\/tutorial\/dart\/images\/dart-lists.png\" alt=\"Dart Lists\"\/><\/figure>\n\n\n\n<p><strong>list1<\/strong>&nbsp;&#8211; It is the&nbsp;<strong>list variable<\/strong>&nbsp;that refers to the list object.<\/p>\n\n\n\n<p><strong>Index &#8211;<\/strong>&nbsp;Each element has its index number that tells the element position in the list. The index number is used to access the particular element from the list, such as list_name[index]. The list indexing starts from&nbsp;<strong>0<\/strong>&nbsp;to&nbsp;<strong>length-1<\/strong>&nbsp;where length denotes the numbers of the element present in the list. For example, &#8211; The length of the above list is 4.<\/p>\n\n\n\n<p><strong>Elements &#8211;<\/strong>&nbsp;The List elements refers to the actual value or dart object stored in the given list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Lists<\/h2>\n\n\n\n<p>The\u00a0Dart\u00a0list can be categorized into two types &#8211;<\/p>\n\n\n\n<ul><li>Fixed Length List<\/li><li>Growable List<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Fixed Length List<\/h3>\n\n\n\n<p>The fixed-length lists are defined with the specified length. We cannot change the size at runtime. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211; Create the list of fixed-size<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var list_name = new List(size)  <\/code><\/pre>\n\n\n\n<p>The above syntax is used to create the list of the fixed size. We cannot add or delete an element at runtime. It will throw an exception if any try to modify its size.<\/p>\n\n\n\n<p>The syntax of initializing the fixed-size list element is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211; Initialize the fixed size list element<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name&#91;index] = value;  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   var list1 = new List(5);   \n   list1&#91;0] = 10;   \n   list1&#91;1] = 11;   \n   list1&#91;2] = 12;   \n   list1&#91;3] = 13;  \n   list1&#91;4] = 14;    \n   print(list1);   \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;10, 11, 12, 13, 14]\n<\/code><\/pre>\n\n\n\n<p><strong>Explaination &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we have created a variable&nbsp;<strong>list1<\/strong>&nbsp;that refers the list of fixed size. The size of the list is five and we inserted the elements corresponding to its index position where 0<sup>th<\/sup>&nbsp;index holds 10, 1<sup>st<\/sup>&nbsp;index holds 12, and so on.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Growable List<\/h3>\n\n\n\n<p>The list is declared without specifying size is known as a Growable list. The size of the Growable list can be modified at the runtime. The syntax of the declaring Growable list is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211; Declaring a List<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ creates a list with values  \nvar list_name = &#91;val1, val2, val3]  \nOr   \n\/\/ creates a list of the size zero  \nvar list_name = new List() <\/code><\/pre>\n\n\n\n<p><strong>Syntax &#8211; Initializing a List<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name&#91;index] = value;  <\/code><\/pre>\n\n\n\n<p>Consider the following example &#8211;<\/p>\n\n\n\n<p><strong>Example &#8211; 1<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   var list1 = &#91;10,11,12,13,14,15];  \n   print(list1);   \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;10, 11, 12, 13, 14, 15]\n<\/code><\/pre>\n\n\n\n<p>In the following example, we are creating a list using the empty list or&nbsp;<strong>List()<\/strong>&nbsp;constructor. The&nbsp;<strong>add()<\/strong>&nbsp;method is used to add element dynamically in the given list.<\/p>\n\n\n\n<p><strong>Example &#8211; 2<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   var list1 = new List();   \n   list1.add(10);   \n   list1.add(11);   \n   list1.add(12);   \n   list1.add(13);  \n   print(list1);   \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;10, 11, 12, 13]\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">List Properties<\/h2>\n\n\n\n<p>Below are the properties of the list.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><th>Property<\/th><th>Description<\/th><\/tr><tr><td>first<\/td><td>It returns the first element case.<\/td><\/tr><tr><td>isEmpty<\/td><td>It returns true if the list is empty.<\/td><\/tr><tr><td>isNotEmpty<\/td><td>It returns true if the list has at least one element.<\/td><\/tr><tr><td>length<\/td><td>It returns the length of the list.<\/td><\/tr><tr><td>last<\/td><td>It returns the last element of the list.<\/td><\/tr><tr><td>reversed<\/td><td>It returns a list in reverse order.<\/td><\/tr><tr><td>Single<\/td><td>It checks if the list has only one element and returns it.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Inserting Element into List<\/h2>\n\n\n\n<p>Dart provides four methods which are used to insert the elements into the lists. These methods are given below.<\/p>\n\n\n\n<ul><li>add()<\/li><li>addAll()<\/li><li>insert()<\/li><li>insertAll()<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">The add() Method<\/h3>\n\n\n\n<p>This method is used to insert the specified value at the end of the list. It can add one element at a time and returns the modified list object. Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<ol><li>list_name.add(element);&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {  \n    var odd_list = &#91;1,3,5,7,9];  \n    print(odd_list);  \n    odd_list.add(11);  \n    print(odd_list);  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;1, 3, 5, 7, 9]\n&#91;1, 3, 5, 7, 9, 11]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we have a list named&nbsp;<strong>odd_list,<\/strong>&nbsp;which holds odd numbers. We inserted a new element 11 using&nbsp;<strong>add()<\/strong>&nbsp;function. The&nbsp;<strong>add()<\/strong>&nbsp;function appended the element at the end of the list and returned the modified list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The addAll() Method<\/h3>\n\n\n\n<p>This method is used to insert the multiple values to the given list. Each value is separated by the commas and enclosed with a square bracket ([]). The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name.addAll(&#91;val1,val2,val3,?..valN]);  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {  \n    var odd_list = &#91;1,3,5,7,9]  \n     print(odd_list);  \n      odd_list.addAll(&#91;11,13,14]);  \n      print(odd_list);  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;1, 3, 5, 7, 9]\n&#91;1, 3, 5, 7, 9, 11, 13, 14]\n<\/code><\/pre>\n\n\n\n<p><strong>Explaination &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we don&#8217;t need to call the&nbsp;<strong>add()<\/strong>&nbsp;function multiple times. The&nbsp;<strong>addAll()<\/strong>&nbsp;appended the multiple values at once and returned the modified list object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The insert() Method<\/h3>\n\n\n\n<p>The&nbsp;<strong>insert()<\/strong>&nbsp;method provides the facility to insert an element at specified index position. We can specify the index position for the value to be inserted in the list. The syntax is given below.<a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<ol><li>list_name.insert(index,value);&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n    List lst = &#91;3,4,2,5];  \n    print(lst);  \n    lst.insert(2,10);  \n    print(lst);  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;3, 4, 2, 5]\n&#91;3, 4, 10, 2, 5]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we have a list of the random numbers. We called the insert() function and passed the index 2<sup>nd<\/sup>&nbsp;value 10 as an argument. It appended the value at the 2<sup>nd<\/sup>&nbsp;index and returned the modified list object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The insertAll() Method<\/h3>\n\n\n\n<p>The insertAll() function is used to insert the multiple value at the specified index position. It accepts index position and list of values as an argument. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name.insertAll(index, iterable_list_of_value)  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n    List lst = &#91;3,4,2,5];  \n     print(lst);  \n     lst.insertAll(0,&#91;6,7,10,9]);  \n     print(lst);  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;3, 4, 2, 5]\n&#91;6, 7, 10, 9, 3, 4, 2, 5]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we have appended the list of values at the 0<sup>th<\/sup>&nbsp;index position using the&nbsp;<strong>insertAll()<\/strong>&nbsp;function. It returned the modified list object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Updating List<\/h2>\n\n\n\n<p>The Dart provides the facility to update the list and we can modify the list by simply accessing its element and assign it a new value. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name&#91;index] = new_value;  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n      var list1 = &#91;10,15,20,25,30];  \n      print(\"List before updation: ${list1}\");  \n      list1&#91;3] = 55;  \n      print(\"List after updation:${list1}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List before updation: &#91;10, 15, 20, 25, 30]\nList after updation: &#91;10, 15, 20, 55, 30]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we have accessed the 3<sup>rd<\/sup>&nbsp;index and assigned the new value 55 then printed the result. The previous list updated with the new value 55.<\/p>\n\n\n\n<p><strong>replaceRange() &#8211;<\/strong>&nbsp;The Dart provides&nbsp;<strong>replaceRange()<\/strong>&nbsp;function which is used to update within the given range of list items. It updates the value of the elements with the specified range. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name.replaceRange(int start_val, int end_val, iterable);  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n      var list1 = &#91;10,15,20,25,30];  \n      print(\"List before updation: ${list1}\");  \n      list1.replaceRange(0,4,&#91;1,2,3,4]) ;  \n      print(\"List after updation using replaceAll() function : ${list1}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List before updation: &#91;10, 15, 20, 25, 30]\nList after updation using replaceAll() function : &#91;1, 2, 3, 4, 30]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we called the&nbsp;<strong>replaceRange()<\/strong>&nbsp;to the list which accepts the three arguments. We passed the starting index 0<sup>th<\/sup>, end index 4 and the list of the elements to be replaced as a third arguments. It returned the new list with the replaced element from the given range.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Removing List Elements<\/h2>\n\n\n\n<p>The Dart provides following functions to remove the list elements.<\/p>\n\n\n\n<ul><li>remove()<\/li><li>removeAt()<\/li><li>removeLast()<\/li><li>removeRange()<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">The remove() Method<\/h3>\n\n\n\n<p>It removes one element at a time from the given list. It accepts element as an argument. It removes the first occurrence of the specified element in the list if there are multiple same elements. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name.remove(value)  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n      var list1 = &#91;10,15,20,25,30];  \n      print(\"List before remove element : ${list1}\");  \n      list1.remove(20) ;  \n      print(\"List after removing element : ${list1}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List before remove element : &#91;10, 15, 20, 25, 30]\nList after removing element : &#91;10, 15, 25, 30]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we called the&nbsp;<strong>remove()<\/strong>&nbsp;function to the list and passed the value 20 as an argument. It removed the 20 from the given list and returned the new modified list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The removeAt() Method<\/h3>\n\n\n\n<p>It removes an element from the specified index position and returns it. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name.removeAt(int index)  <\/code><\/pre>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n      var list1 = &#91;10,11,12,13,14];  \n      print(\"List before remove element : ${list1}\");  \n      list1.removeAt(3) ;  \n      print(\"List after removing element : ${list1}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List before remove element : &#91;10, 11, 12, 13, 14]\nList after removing element : &#91;10, 11, 12, 14]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we passed the 3<sup>rd<\/sup>&nbsp;index position as an argument to the&nbsp;<strong>removeAt()<\/strong>&nbsp;function and it removed the element 13 from the list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The removeLast() Method<\/h3>\n\n\n\n<p>The removeLast() method is used to remove the last element from the given list. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax-<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name.removeLast()  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s understand the following example.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n     var list1 = &#91;12,34,65,76,80];  \n     print(\"List before removing element:${list1}\");  \n     list1.removeLast();  \n     print(\"List after removed element:${list1}\");  \n  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List before removing element:&#91;12, 34, 65, 76, 80]\nList after removed element:&#91;12, 34, 65, 76]\n<\/code><\/pre>\n\n\n\n<p>In the above example, we called the removeLast() method, which removed and returned the last element&nbsp;<strong>80<\/strong>&nbsp;from the given list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The removeRange() Method<\/h3>\n\n\n\n<p>This method removes the item within the specified range. It accepts two arguments &#8211;&nbsp;<strong>start index<\/strong>&nbsp;and&nbsp;<strong>end index.<\/strong>&nbsp;It eliminates all element which lies in between the specified range. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list_name. removeRange();  <\/code><\/pre>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n     var list1 = &#91;12,34,65,76,80];  \n     print(\"List before removing element:${list1}\");  \n     list1.removeRange(1,3);  \n     print(\"List after removed element:${list1}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List before removing element:&#91;12, 34, 65, 76, 80]\nList after removed element:&#91;12, 76, 80]\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we called the&nbsp;<strong>removeRange()<\/strong>&nbsp;method and passed start index position 1 and end index position 3 as an arguments. It removed all elements which were belonging in between the specified position.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Dart Iterating List elements<\/h2>\n\n\n\n<p>The Dart List can be iterated using the&nbsp;<strong>forEach<\/strong>&nbsp;method. Let&#8217;s have a look at the following example.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-lists#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main(){  \n     var list1 = &#91;\"Smith\",\"Peter\",\"Handscomb\",\"Devansh\",\"Cruise\"];  \n     print(\"Iterating the List Element\");  \n     list1.forEach((item){  \n     print(\"${list1.indexOf(item)}: $item\");  \n });  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Iterating the List Element\n0: Smith\n1: Peter\n2: Handscomb\n3: Devansh\n4: Cruise<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dart List is similar to an array, which is the ordered collection of the objects. The array is the most popular and commonly used collection in any other programming language. The Dart list looks like the JavaScript array literals. The syntax of declaring the list is given below. The Dart list is defined by storing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[917],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3576"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=3576"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3576\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=3576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=3576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=3576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}