Lesson 15 of 34
Array Algorithms: Reverse, Search, Sort
10 min 30 XP
The java.util.Arrays class has handy helpers: Arrays.toString() prints an array neatly and Arrays.sort() sorts it.
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.Interviews often ask you to do it without library help. To reverse an array, swap from both ends and meet in the middle (the two-pointer technique).
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.Swapping two values needs a temp variable to hold one of them.