List

 /// Lists : In Dart, arrays are List objects and elements are ordered in sequence in a LIST

/// Types of List : Fixed Length List & Growable List

/// List Collection
void main() {
/// 1st Way to declare List
// List lst = [10, 20, 30]; //This is the Dynamic Type Growable List
// print(lst);

/// 2nd Way to declare List
// List lstn;
// lstn = [40, 50, "Hello", 2.44];
// print(lstn);

/// 3rd Way to declare List
// List lsnew = [1.1, 2.2, 3.3];
// print(lsnew);
// lsnew = ["std1", "std2", "std3"];
// print(lsnew);

/// Particularly Specifying Data Type in List
// List<String> lst1 = ["Hello", "How", "are", "you", "?"];
// print(lst1);

// List<double> lst2 = [1.1, 2.89, 4, 1];
// print(lst2);

/// Print particular List Value
// List prt = [1.1, 2.33, 5.21, "Hello", "Hii", 4,];
// print(prt[1]);
// print(prt[3]);
// print(prt[5]);

/// Updating List Values
// List upd = [1.1, 2.2, 3.3];
// upd[1] = 50;
// upd[2] = 88;
// print(upd);

/// Add new element in List
// List ltr = [1.1, 2.2, 3.3];
// ltr.add(44);
// ltr.add(20);
// print(ltr);

/// Remove element in List
// List cha = [1.1, 2.2, 3.3, "Hello", 50];
// cha.remove("Hello");
// cha.remove(50);
// print(cha);

/// for in loop to printing all elements of List
// List lo = [22, 40, 11, 33, 60];
// for(int i in lo) {
// print(i);
// }

/// Another Example of printing all elements of List using for in loop
// List exam = [2.2, 5.90, 1.44, 8.7];
// for(double x in exam) {
// print(x);
// }

/// Constant List
//Here,list is constant so addition, updation, deletion...are Unsupported operation OR unmodifiable
// List num = const [2, 44, 3.99, 5.88, 1.33, 7];
// //num.add(99); //Not supported OR unmodifiable
// //num[0] = 33; //Not supported OR unmodifiable
// print(num);

/// List Methods

// List a = [10, 20, 30, 40, 50, 60];
// print(a);

// a.add(70);
// print(a);

// a.addAll([80, 90, 100]);
// print(a);

// ListName.insert(indexNumber, Value);
// a.insert(0, 44);
// a.insert(0, 89);
// a.insert(4, 77);
// a.insert(9, 100);
// print(a);

// print(a.first); // printing First element of the List
// print(a.last); // printing Last element of the List

/// Removing element from List
// a.remove(30); // Passing value in parameter
// print(a);

// a.removeAt(2); // Passing index in parameter
// print(a);

// a.removeLast(); //Removing Last element in List
// print(a);

/// New List of elements
// List b = [100, 56, 70, 50, 40, 22, 10, 65, 73, 43];

// b.sort(); // Sorting the elements of List
// print(b);

// b.shuffle(); // Randomly arranges the elements
// print(b);

//print(b.length); //Length of the List

//print(b.reversed); //Reversing the List elements

//print(b.runtimeType); //printing the Type of List (Here, above List is Dynamic)

//print(b.isEmpty); //printing boolean whether Given List is empty OR not

//print(b.isNotEmpty);

// b.clear(); //Clearing the List Elements
// print(b);

/// Combining Two List Elements with No Repeatation of elements
// Creating lists
// List a = [1, 3, 4, 5, 7];
// List b = [5, 7, 8, 9, 10];
//
// // Combining lists
// var c = a + b;
//
// // Printing combined list
// print(c.toSet().toList());
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter