public class ArrayExample { // return an array public static int[] createArray(){ int[] binary = new int[8]; int product=1; for (int i=0; i < binary.length; i++) { binary[i] = product; product = 2 * product; } return binary; } // take an array as a parameter public static void displayArray(int[] numbers){ for (int i=0; i < numbers.length; i++) { System.out.println(numbers[i]); } } // swap method shows that array is pass by value // changes to array apply to method arguments public static void swap(int[] pList, int i, int j){ int temp = pList[i]; pList[i] = pList[j]; pList[j] = temp; } public static void main(String[] args) { // how to use arrays in methods int[] list; list = createArray(); // returns an array, assigned to list displayArray(list); // list is argument to displayArray System.out.println("--------------"); // swap items (same result regardless of index order) swap(list, 0, 5); displayArray(list); } }