dart

How to declare a jagged array in Dart


I have been googling for 2 days now and I have not found how to create a jagged list(array) in Dart. There is this Dart - How to initialize a jagged array? but the given answer makes a normal list(array), what i want is something like this:enter image description here


Solution

  • Not sure I understand the question. But is it something like this where we create a list of lists where each list in the list has a different length?

    void main() {
      final arr = [
        [10, 9, 8],
        [7, 5, 6, 88],
        [30, 15],
        [90],
        [10, 20, 30, 40, 50]
      ];
    
      print(arr); // [[10, 9, 8], [7, 5, 6, 88], [30, 15], [90], [10, 20, 30, 40, 50]]
    }