Concatenating Large Number Of String the Right Way #DartTip

Concatenation of Strings can be done in a variety of ways in Dart. But to glue large number of strings together needs more extra care when you’re looking at performance pertaining saving memory and less execution time.

string1 + string2. This is the most straightforward. This the easiest when it comes to smaller and readability apart from String interpolation.

However, each time you call “+” there is a performance hit and when you concatenate two strings you create a new object which needs to be garbage collected. This create lot of temporary objects, which is inefficient. (Also note, calling the + on null value throws an exception).

Here is an example:

Using the StringBuffer class in the other hand can gather the components quite efficiently and convert them to a string only when needed.

Here is an example:

Happy Coding New Year!!!

--

--

--

Loves clean codes. I build stuff using flutter/dart⚡️

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Reporting on Agile Projects Without Compromising Agile Principles

Getting Started with Terrain Tools in Unity Part 2: Textures and Trees

</ OverTheWire > Bandit Level 25 → Level 26

Most of the Time in Software Development, The World Doesn’t End

Dynamic and Static Libraries

3 Channel Thermometer

Dev Notes | 14/06/2021–27/06/2021

Automatic Email Attachments Retrieval and Invoice Detection with OCR in Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paul Edeme’kong

Paul Edeme’kong

Loves clean codes. I build stuff using flutter/dart⚡️

More from Medium

Flutter: code push to get APK on slack

Style Random : Random string generator with easy syntax and many complex options

How to use webSocket and GetX in Flutter with Architecture

Track Dialog States in Flutter #FlutterTips