Dart Programming Language Collections and String Operations
Dart Programming Language Collections and String Operations
Introduction: Why Are Collections and Strings Important in Dart?
The Dart programming language is a powerful and flexible language that is increasingly popular in mobile and web application development processes. In Dart, collections (List, Map, Set) and string operations are indispensable both for storing and processing data. Especially when developing mobile applications with Flutter, knowing these structures provides a great advantage for fast and efficient data manipulation.
Thanks to the rich functions Dart offers for collections and string operations, you can make your code more readable and easier to maintain. So, how are collections created and how are string operations performed in Dart? Let's examine it step by step with different practical examples.
Dart Collections: Using List, Map, and Set
Defining and Using Lists (Arrays)
void main() {
List<int> numbers = [1, 2, 3, 4];
numbers.add(5);
print(numbers); // [1, 2, 3, 4, 5]
}
List is used to store elements sequentially in Dart. You can add new elements with add(). Also, many useful methods such as remove(), length, forEach() allow you to perform operations quickly.
Using Map (Key-Value Structure)
void main() {
Map<String, int> grades = {'Ahmet': 90, 'Ayşe': 85};
grades['Kemal'] = 78;
print(grades['Ahmet']); // 90
}
In Map collections, each value is accessed with a key. This structure is especially useful for table and dictionary type data.
Unique Collections with Set
void main() {
Set<String> fruits = {'Elma', 'Armut', 'Elma'};
print(fruits); // {Elma, Armut}
}
In a Set collection, the same element cannot exist more than once. Thus, uniqueness is guaranteed in your data set.
String Operations with Dart Programming Language
Basic String Definition and Concatenation
void main() {
String name = 'Dart';
String greeting = 'Hello, ' + name + '!';
print(greeting); // Hello, Dart!
// String interpolation
print('Greetings, $name!');
}
In Dart, string concatenation is easy both with + and by using $. String interpolation increases readability.
String Splitting, Conversion, and Character Count
void main() {
String sentence = 'Dart programming language';
List<String> words = sentence.split(' ');
print(words); // [Dart, programming, language]
print(sentence.toUpperCase()); // DART PROGRAMMING LANGUAGE
print(sentence.length); // 21
}
On String, you can perform splitting with split(), conversion with toUpperCase() or toLowerCase(). You get the character count with length.
Conclusion: Practical Codes with Collections and Strings in Dart
With collections and string operations, the Dart programming language offers both powerful data structures and user-friendly string functions. You can easily manage data with List, Map, and Set; and perform practical operations on texts with the String class. Mastering collections and string operations in Dart allows you to develop higher-quality and more sustainable applications.

Yorum Gönder