List in Dart
Tags: dart, todayilearned, beginners
Published: 2019-09-16 04:02:56

* Consider a situation where we need to store five String values. If we use programming's simple variable and data type concepts, then we need five variables of String data type.

* It seems simple because we had to store just five String values. Now let's assume we have to store 10000 String values. Now its too much time consuming to create 10000 variables.

* To overcome this kind of situations we have a concept called Collections.

* Collections are used to store data.

In dart, collections can be classified into four basic categories:
1. List
2. Map
3. Set
4. Queue

But the **list** and **map** are mostly used. Set and queue are used in some special cases.

##List
***

* The list is a collection of data having the same data type. In other languages **List** is called **Array**.

* In list, data is stored in an ordered way.
* Every individual element of the list can be accessed by its index number. The index number always starts from 0.

There are two types of list:

1. Fixed length list
2. Growable list

###Fixed Length List

* In the fixed length list once the length of the list is defined it cannot be changed during run time.

####Syntax
```dart
List <data type> list_name = List (length of list);
```

####Sample Code

```dart
main() {
  List<int> marks = List(5);
  marks[0] = 25;    // Inserting values to list
  marks[1] = 35;
  marks[2] = 65;
  marks[3] = 75;
  marks[4] = 63;

  for (int elements in marks) {
    print(elements);
  }
}

Output
25
35
65
75
63
```

###Growable List

* The length of Growable list is dynamic. It can be changed during run time.

####Syntax
```dart
List <data type> list_name = List (); // Way 1
List <data type> list_name = [element1, element2]; // Way 2
```
####Sample Code
```dart
main() {

  List<String> countries = ["India", "Nepal"];
  for (String elements in countries) {
    print(elements);
  }
}

Output
India
Nepal
```

So, guys, That’s it for a list. As I always say practice it, understand it conceptually. Till then Keep Loving, Keep Coding. And just like always I’ll surely catch you up in the next article. 😊


Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

###For More Information Please Visit Following Links
* [Fuchsia OS official site](https://fuchsia.dev/)
* [Dart official site](https://dart.dev/)
* [Flutter official site](https://flutter.dev/)


Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

- [My Site] (https://www.jaytillu.in)
- [My Blogs] (https://blogs.jaytillu.in)
- [Twitter](https://twitter.com/jay_tillu)
- [Facebook](https://www.facebook.com/jaytillu.1314/)
- [Instagram](https://www.facebook.com/jaytillu.1314/)
- [Medium](https://medium.com/jay-tillu)
- [LinkedIn](https://www.linkedin.com/in/jaytillu/)
- [Github](https://www.github.com/jay-tillu)
- [Stack overflow](https://stackoverflow.com/users/8509590/jay-tillu)
or just mail me at jd.tillu@gmail.com