← Back to Question List
Java Code Walkthrough #43
Generic Swap Method
📄 Code
Read carefully — what does this print?1import java.util.Arrays;23public class Main {4 public static <T> void swap(T[] arr, int i, int j) {5 T temp = arr[i];6 arr[i] = arr[j];7 arr[j] = temp;8 }910 public static void main(String[] args) {11 String[] words = {"cat", "dog", "bird"};12 swap(words, 0, 2);13 System.out.println(Arrays.toString(words));14 }15}