---
# System prepended metadata

title: Reverse an array

---

# Reverse an array

## Assignment

Write a method that returns an array in reverse order:

`[1, 2, 3, 4]` →`[4, 3, 2, 1]`

```java 
public static int[] reverseArray(int[] toReverse) {
    int[] reversed = new int[toReverse.length];
    for(int i = 0; i < toReverse.length; i++)       {
        reversed[i] = toReverse[toReverse.length-1-i];
    }
    return reversed;
}

```
Zeitkomplexität O(n)
Platzkomplexität O(n)
```

