Skip to content

Commit

Permalink
Fixed-length List
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Sep 2, 2018
1 parent 94f766e commit 707ab66
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 31_list_fixed_length.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

// Objectives
// 1. Fixed-length list

void main() {

// Elements: N N N N N
// Index: 0 1 2 3 4

List<int> numbersList = List(5); // Fixed-length list
numbersList[0] = 73; // Insert operation
numbersList[1] = 64;
numbersList[3] = 21;
numbersList[4] = 12;

numbersList[0] = 99; // Update operation
numbersList[1] = null;// Delete operation

print(numbersList[0]);
print("\n");

// numbersList.remove(73); // Not supported in fixed-length list
// numbersList.add(24); // Not supported in fixed-length list
// numbersList.removeAt(3); // Not supported in fixed-length list
// numbersList.clear(); // Not supported in fixed-length list

for (int element in numbersList) { // Using Individual Element (Objects)
print(element);
}

print("\n");

numbersList.forEach((element) => print(element)); // Using Lambda

print("\n");

for (int i = 0; i < numbersList.length; i++) { // Using Index
print(numbersList[i]);
}
}

0 comments on commit 707ab66

Please sign in to comment.