List_(Collection)_Dart

 import "dart:core";


//A very commonly used collection in programming is an array. Dart represents arrays in the
// form of List objects. A List is simply an ordered group of objects. The dart:core library
// provides the List class that enables creation and manipulation of lists
void main()
{
var play = ["apple", "mango", "watermelon", true, 32, 11, 80.12, 31.82, false];
print(play);

//Add Element
play.add("coconut");
print("Add : ${play}");

//addAll() Insert the multiple values to the given List, and each value is
// separated by the commas and enclosed with a square bracket ([])

play.addAll([32, "pomegranate", true]);
print("addAll() : ${play}");

//Creating New List
var play1 = [52,96,36,10,74,55,14,39,64,25,75,31,54,61,85,59];

//sort element
play1.sort();
print("sort element : ${play1}");

//print using for Each loop
for(var a in play1)
{
print(a);
}

//Insert list in specific position
//Syntax : List_Name.insert(index, element);
play1.insert(2, 100);
print("Insert List in Specific position : ${play1}");

//insertAll() Insert the multiple value at the specified index position
//Syntax : List_Name.insertAll(index, [List_elements]);
play1.insertAll(1, [10, 20, 30, 40]);
print(play1);

//Remove element from specific position
play1.removeAt(1);
print(play1);

//Remove element from the List
play1.remove(100);
print(play1);

//Remove Last element from the List
play1.removeLast();
print("Remove Last Element : ${play1}");

//removeRange() Removes the item within the specified range
play1.removeRange(0, 4);
print("Remove Range : ${play1}");

//Find List Length
print(play1.length);

//Reversed List
// print(play1.reversed);

//Check Element it contain in List(Returns boolean : true OR false)
print(play1.contains(75));
print(play1.contains(100));

//print First Element
print(play1.first);

//print Last Element
print(play1.last);

//single: It is used to check if the List has only one element and returns it.
// The value is null if the iterable is empty or it contains more than one element

print(play1.singleOrNull);

//Creating new List below :
// var play2 = [62];
// print(play2.singleOrNull);

//isNotEmpty: It returns true if the List is not empty and false if the List is empty
print(play1.isNotEmpty);

//isEmpty: It returns true if the List is empty and false if the List is not empty
print(play1.isEmpty);

}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter