Arrays

In the previous chapter we learned the importance of data, groups, vectors, tuples, const data and shared data and how to use all of them. With all these concepts we now developed a good understanding of Flint's type-system. So, its now time to move to more complex types than those of the last chapter: arrays.

What are Arrays?

An array is a collection of the same type which can be resized and filled with values. While vectors and tuples are great for storing a small amount of values, what if we want to store a hundred of them? Using a tuple to store 100 elements would not only be extremely tedious but also extremely verbose. Just imagine writing i32, a hundred times inside the data<..> type.

You already know an array type: Strings! The str type is just an array of characters (u8) but you will also learn how strings work under the hood in this chapter!

Why are Arrays Important?

Arrays are essential in programming because they allow you to:

  • Store and manipulate large amounts of data
  • Perform operations on multiple values in chunks
  • Use indexing to access specific values in the array

What to Expect

In this chapter, we will conver the following topics:

  • Declaring and using arrays
  • Accessing and modifying array elements
  • Using arrays in functions and data components
  • What strings and arrays have in common with one another
  • What ranges are and how to use them
  • The enhanced for loop, what it is and how it works
  • Multi-dimensional arrays and access patterns
  • How groups can be used together with arrays
  • Best practices for working with arrays