• Courses
  • YouTube
  • Dev News
  • Technology
  • Blogs
  • Flutter Jobs
  • Contact
    • About Us
    • RegisterLogin
    Navoki
    • Courses
    • YouTube
    • Dev News
    • Technology
    • Blogs
    • Flutter Jobs
    • Contact
      • About Us
    • RegisterLogin

      List in Dart Programming language

      • Home
      • All courses
      • Dart Programming Language
      • List in Dart Programming language
      CoursesDart Programming LanguageDart TutorialList in Dart Programming language
      • List
        6
        • Lecture1.1
          Video- List in Dart
        • Lecture1.2
          What is a List in Dart?
        • Lecture1.3
          Declare a List in Dart
        • Lecture1.4
          Traverse a List in Dart
        • Lecture1.5
          Add and Remove items in List
        • Lecture1.6
          Useful functions in List

        Traverse a List in Dart

        In the previous lesson, we declared a List, now we have to access each element from the list. there are many ways who achieved this we will be discussing only the most used of them.

        forEach()

        forEach() extract items from the List one by one and return item in function in forEach, element extracted here are in sequential order

        void main() {
        List<String> movies=["Avengers","IronMan","Harry Potter-I","Harry Potter-II"];
         
        movies.forEach((movie){
           print(movie);
        });
          
        }

        OUTPUT

        Avengers
        IronMan
        Harry Potter-I
        Harry Potter-II
        
        

        There is another sentence of forEach :

        void main() {
        List<String> movies=["Avengers","IronMan","Harry Potter-I","Harry Potter-II"];
         
        for(String str in movies){
           print(str);
        }
        }

        OUTPUT

        Avengers
        IronMan
        Harry Potter-I
        Harry Potter-II

        for Loop

        But sometimes you require items as well as index number also so for that we can use the basic for loop syntax

        void main() {
        List<String> movies=["Avengers","IronMan","Harry Potter-I","Harry Potter-II"];
         
        for(int i=0;i<movies.length;i++){
           print("Index $i, Item= ${movies[i]}");
        }
        }
        
        

        OUTPUT

        Index 0, Item= Avengers
        Index 1, Item= IronMan
        Index 2, Item= Harry Potter-I
        Index 3, Item= Harry Potter-II
        
        
        0
        Prev Declare a List in Dart
        Next Add and Remove items in List

        DON’T MISS
        FLUTTER UPDATES

        Be the first to know when our blog is published.

        flutter-mobile-mockup

        Check your inbox or spam folder to confirm your subscription.

        Contact

        •   Navoki Technologies Pvt. Ltd.
          JMD Megapolis , Sector 48, Gurugram, Haryana 122018

        Company

        • About Us
        • Blogs
        • Contact
        • Privacy policy
        • Terms & Condition

        Useful Links

        • Courses
        • Youtube
        • Dev News

        Mobile

        Click and Get started in seconds

        "Navoki" is a registered trademark of Navoki.com ® 2020–2030 Navoki Technologies Pvt Ltd.

        • Terms & Condition

        Login with your site account

        Continue with Google

        By "Sign in” above to accept Navoki’s Terms of Service & Privacy Policy.

        Not a member yet? Register now

        Register a new account

        Continue with Google

        By "Sign Up” above to accept Navoki’s Terms of Service & Privacy Policy.

        Are you a member? Login now

        Modal title

        Message modal