MeshWorld India LogoMeshWorld.
DartTutorial2 min read

How to find the length of a list in Dart

Listen to ArticleAI Speech
~2 min read narration
100%
How to find the length of a list in Dart

List in Dart is a collection of objects. The duplicate entry in a list is also allowed.

This article shows how to find the length of a list in Dart.

The property named length is used to get the number of objects in a list.

The list can be classified as −

  • Fixed Length List
    • A list whose length cannot be changed at runtime is known as a fixed-length list.
  • Growable List
    • A list whose length can change at runtime is known as a growable list.

A list is simply an ordered and mutable group of objects.

Starting index of the list is 0(zero) through length - 1.

The length property

The list in Dart provides a property length that returns the total objects within a list.

Syntax

listName.length

The length property gives an integer value i.e the number of objects within the list.

Example

void main()
{
  var countries = ["India 🇮🇳", "Switzerland 🇨🇭", 1, -9.5, 0, 1];
  print(countries);
  print('Total elements : ${countries.length}');
}

Output:

[India 🇮🇳, Switzerland 🇨🇭, 1, -9.5, 0, 1]
Total elements : 6

The list has 6 elements.

Another way to get the length of a list is by using looping structure but the more preferable way is to use the length property of a list.

Conclusion

To find the length of a list in Dart, use the length property of a list.

Hope you like this!

Keep helping and happy 😄 coding

Reader Quality Feedback

Did this technical guide help solve your problem?

Suggest Errata ($0)
Leo
Primary Author

Leo

Mobile Solutions Architect and Flutter enthusiast. Expert in building high-performance cross-platform applications and native mobile experiences.

Explore Author Archive
Compute Fuel & Open Testbed
100% Independent & Verified

Fuel High-Density, Zero-Fluff Engineering Deep-Dives

Every guide on MeshWorld is validated on physical Linux nodes and reproducible testbeds. If this article saved you hours of debugging or unblocked production, consider funding our next cluster run.

Weekly Dispatch

Join MeshWorld Dispatch

Get practical tutorials, system blueprints, and curated AI engineering notes straight to your inbox. No fluff, zero spam.

Zero spam. 1-click unsubscribe anytime.Prefer RSS?
Curated Continuations

Up Next in This Domain.

Browse Full Archive