• 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

        Add and Remove items in List

        Till now we already have the data to store in List at the time of declaration. now we want to add data dynamically during execution, for that we use add(). The syntax is like this

        void main() {
        List<String> movies=List();
        
          print("1. $movies");
          movies.add("Venom");
          print("2. $movies");
          
          movies.add("Hulk");
          print("3. $movies");
        }

        OUTPUT

        1. []
        2. [Venom]
        3. [Venom, Hulk]

        So, as you can see here whenever data is added the sequence is maintained. Now in the same program let’s try to remove data. If you have data types like integer, boolean, String then you can directly mention the item name in remove() , you can also remove items by measuring the index number in removeAt(index)

        void main() {
        List<String> movies=List();
            print("1. $movies");
            movies.add("Venom");
            print("2. $movies");
          
           movies.add("Hulk");
           print("2. $movies");
          
           movies.remove("Venom"); // remove by itemName
           print("3. $movies");
          
           movies.removeAt(0);    // remove by index
           print("4. $movies");
          
        }
        

        OUTPUT

        1. []
        2. [Venom]
        2. [Venom, Hulk]
        3. [Hulk]
        4. []

         

        0
        Prev Traverse a List in Dart
        Next Useful functions 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