Reverse array elements in Julia - reverse(), reverse!() and reverseind() Methods
Last Updated :
12 Jul, 2025
The
reverse()
is an inbuilt function in
julia which is used to reverse the specified vector
v from start to stop.
Syntax:
reverse(v, start, stop)
or
reverse(A; dims::Integer)
Parameters:
- v: Specified vector.
- start: Specified starting value.
- stop: Specified stopping value.
- A: Specified array.
- dims::Integer: Specified dimensions.
Returns: It returns a reversed copy of the vector.
Example 1:
Python
# Julia program to illustrate
# the use of reverse() method
# Getting the reversed copy of
# the specified vector.
A = Vector(2:8)
println(reverse(A))
println(reverse(A, 3, 6))
println(reverse(A, 7, 4))
Output:
[8, 7, 6, 5, 4, 3, 2]
[2, 3, 7, 6, 5, 4, 8]
[2, 3, 4, 5, 6, 7, 8]
Example 2:
Python
# Julia program to illustrate
# the use of reverse() method
# Getting reversed array in
# the specified dimension
A = [5 10; 15 20]
println(reverse(A, dims = 1))
println(reverse(A, dims = 2))
Output:
reverse!()
The
reverse!()
is an inbuilt function in
julia which is In-place version of reverse() function.
Syntax:
reverse!(v, start, stop)
Parameters:
- v: Specified vector.
- start: Specified starting value.
- stop: Specified stopping value.
Returns: It returns a reversed copy of the vector.
Example:
Python
# Julia program to illustrate
# the use of reverse !() method
# Getting the reversed copy of
# the specified vector.
A = Vector(2:8)
println(reverse !(A))
println(reverse !(A, 3, 6))
Output:
[8, 7, 6, 5, 4, 3, 2]
[8, 7, 3, 4, 5, 6, 2]
reverseind
The
reverseind()
is an inbuilt function in
julia which is used to return the corresponding index in v so that v[reverseind(v, i)] == reverse(v)[i], where i is the given index.
Syntax:
reverseind(v, i)
Parameters:
- v: Specified string.
- i: Specified index.
Returns: It returns the corresponding index in v so that v[reverseind(v, i)] == reverse(v)[i].
Example:
Python
# Julia program to illustrate
# the use of reverseind() method
# Getting the corresponding index in v
# so that v[reverseind(v, i)] == reverse(v)[i]
V = reverse("Geeks")
for i in 1:length(r)
print(V[reverseind("Geeks", i)])
end
Output:
Similar Reads
Reverse a string in Julia - reverse() Method The reverse() is an inbuilt function in julia which is used to return the reverse of the specified string. Syntax: reverse(s::AbstractString) Parameters: a::AbstractString: Specified string Returns: It returns the reverse of the specified string. Example 1: Python # Julia program to illustrate # the
1 min read
Creating a view of parent array in Julia - view(), @view and @views Methods The view() is an inbuilt function in julia which is used to return a view into the given parent array A with the given indices instead of making a copy. Syntax: view(A, inds...) Parameters: A: Specified parent array. inds: Specified indices. Returns: It returns a view into the given parent array A w
2 min read
Creating array with repeated elements in Julia - repeat() Method The repeat() is an inbuilt function in julia which is used to construct an array by repeating the specified array elements with the specified number of times. Syntax: repeat(A::AbstractArray, counts::Integer...) or repeat(A::AbstractArray; inner, outer) or repeat(s::AbstractString, r::Integer) or re
2 min read
Set elements at a given index of array in Julia - setindex!() Method The setindex!() is an inbuilt function in julia which is used to store values from the given array X within some subset of A as specified by inds. Syntax: setindex!(A, X, inds...) Parameters: A: Specified function.X: Specified array.inds: Specified index. Returns: It does not return any values.
1 min read
Replacing elements of a collection in Julia - replace() and replace!() Methods The replace() is an inbuilt function in julia which is used to return a copy of the specified array with different types of replacement. These all operations are illustrated with below examples. Syntax: replace(A, old_new::Pair...; count::Integer) or replace(new::Function, A; count::Integer) Paramet
3 min read
Reshaping array as a vector in Julia - vec() Method The vec() is an inbuilt function in julia which is used to reshape the specified array as a one-dimensional column vector i.e, 1D array. Syntax: vec(a::AbstractArray) Parameters: a::AbstractArray: Specified array. Returns: It returns the reshaped 1D array. Example 1: Python # Julia program to illust
2 min read