Julia is a high performance, dynamic programming language that is easy to use as it has a high-level syntax. It is free for everyone to use. Julia does not give a lot of attention to implementing arrays, so there is a lesser load on the compiler. An array in Julia is represented in a multi-dimensional grid and can contain any type of data. Julia allows us to create arrays not only by creating array variables but also as literals. We will discuss various features of the array literals offered by Julia in this article.
Array Literals
Arrays can be directly constructed in Julia without creating a corresponding variable with the use of square braces with the syntax - [element1, element2, . . . ]. This creates a one-dimensional array where the elements are the ones that are separated by commas in the arguments as shown below:
Julia
# Creating Array of four elements
[11, 22, 33, 44]

Type of an array literal
The type of the array is determined by the type of the elements present in it. If all the elements are of the same type, then the array type will be the same. But if they are different, to get a definitive type for the array we can convert the types of the elements to their promotion types using promote() function.
Julia
# Changing the type of the array
# to the promoted type of the elements
promote(12, 2.3, 4//5)
[12, 2.3, 4//5]
Â
Â

Â
If we do not perform this promoting operation an array that can hold any type is produced as shown below:
Â
Julia
# Creating an empty array
[]
# Creating an array with different types of elements
[11, 3//5]
Â
Â

Concatenation of Arrays
Vertical concatenation
Â
The concatenation of elements in an array is performed by placing a semicolon ( ; ) Â or a new line between them. These elements will be vertically concatenated. But if a comma is placed between the elements instead of the semicolon, Julia just considers them as elements as shown below:
Â
Julia
# No concatenation error occurs,
# but they are treated as elements
# for the array literal
[1:3, 4:7]

As mentioned above we're separating the elements with a semicolon to perform vertical concatenation:
Julia
# Concatenation using semicolons
[1:3; 4:7]
Â
Â

Â
We could also just represent the array in new lines to perform the concatenation vertically as shown below:
Â
Julia
# Concatenation using spacing
[1:2
3:5
6]
Â
Â

Horizontal concatenationÂ
Â
To concatenate the array horizontally we place tabs or spaces between the elements instead of commas. If we do not place the tabs Julia considers the whole argument as one element. We concatenate various types of elements like range elements, array elements, and normal numbers as shown below:
Â
Julia
# Horizontal concatenation
[1:2 3:4 5:6]
# Elements can also be written in the inner braces
[[1,2] [3,4] [5,6]]
# Just normal numbers can also be concatenated
[11 22 33]
Â
Â

Multi-directional concatenation
Â
To concatenate both horizontally and vertically we can place newlines and spacing between the elements respectively together without placing commas as shown below:
Â
Julia
# Concatenating horizontally and
# vertically in an array literal
[2 4
6 8]
Â
Â

Â
The following example shows the use of zeros() function to fill up some spaces with zeros in a 2D space in the array, vertically concatenate 3 and 6 by placing a semi-colon, a new line to concatenate vertically, and spacing to concatenate 7, 8, and 9 horizontally, which ultimately produces a 3x3 matrix.
Â
Julia
# Concatenating four elements horizontally
# and vertically in an array literal
[zeros(Int, 2, 2) [3; 6]
[7 8] 9]
Â
Â
Â
Â
Â

Typed array literalsÂ
Â
An array of a specific type can be generated with the syntax - T[element1, element2, . . . ], where T is the type you want the array to be. Implementing an array with this syntax creates an array which initializes the type to all the elements in it. The following example shows the initialization of the Int8 type to the elements of the array, but we can also put any other type we desire.
Â
Julia
# Creating an array literal
[[1 3] [2 4]]
# Creating a typed array literal of the type Int8
Int8[[1 3] [2 4]]
# Creating a typed array literal of the type Any
Any[[1 3] [2 4]]

Similar Reads
Arrays in Julia
Arrays in Julia are a collection of elements just like other collections like Sets, Dictionaries, etc. Arrays are different from Sets because arrays are ordered collection of elements, and can hold duplicate values, unlike sets which require all the elements to be unique. Arrays are N-Dimensional co
13 min read
Cell Arrays in Julia
Cell array is an abstract data type with indexed data containers called cells, where each cell can contain any type of data. It is normally used in Matlab to store data.Coming to Julia, one of the magical things about Julia is its type system. It is a strictly typed language. In Julia, arrays can co
5 min read
Sorting of Arrays in Julia
The process of arranging the given data in a particular order or manner depends on the output. It is storing of data in sorted order. Sorting can be done in two ways i.e in ascending and descending order. Sorting can be performed using sorting algorithm or sorting functions. So, in sorting the progr
8 min read
Format Specifiers in Julia
Format Specifiers are used to format the Input and Output of a Programming language. It tell the compiler about the data type of the Input that is being passed to it. Julia contains a package Printf and using its macro @printf takes input string value to be formatted and accepts parameters as variab
4 min read
Tasks in Julia
Tasks are a control flow feature that allows computations to be suspended and resumed in a flexible manner. It is useful for IO-bound tasks, network files etc. The benefits of tasks are less memory and quick processing. It provides a function named task() to create any function as a task. The origin
3 min read
Variables in Julia
Variables are some names given to the memory location to which they are assigned. These memory locations are used to store values that can be accessed by using the name of the location, i.e. Variable. Unlike C and Java, variables in Julia need not to be written with a Datatype. Julia auto-assigns th
4 min read
Tuples in Julia
Tuples in Julia are an immutable collection of distinct values of same or different datatypes separated by commas. Tuples are more like arrays in Julia except that arrays only take values of similar datatypes. The values of a tuple can not be changed because tuples are immutable. Tuples are a hetero
2 min read
Operators in Julia
Operators in Julia are the mathematical symbols that are used to perform operations on variables and values. These symbols are used to carry out arithmetic and logical computations. Variables on which the operators perform operations are termed as Operands. In other words, we can say that an operato
9 min read
Array Interfaces in Julia
An array interface is a syntactical contract for arrays in Julia that they must follow. This article describes the various methods which can be adopted to construct array interfaces in Julia. It also explains how to perform indexing in an array interface to access its elements. An array interface ca
5 min read
Vectors in Julia
Vectors in Julia are a collection of elements just like other collections like Array, Sets, Dictionaries, etc. Vector are different from Sets because vectors are ordered collections of elements, and can hold duplicate values, unlike sets which require all the elements to be unique. Vectors are one-d
5 min read