TestSync.java
Select all
/* TestSync.java CIS 260 2/16/2005 David Klick Demonstrates how a List and an array of Object references can be tied together so changes in the List change the associated array. Note: This program requires Java 1.5 or later to compile. */ import java.util.*; public class TestSync { public static void main(String[] args) { Integer[] arr = { new Integer(10), new Integer(5), new Integer(3), new Integer(6), new Integer(7), new Integer(18) }; List
lst = Arrays.asList(arr); // display original array of Integer objects System.out.println(Arrays.toString(arr)); // make change to associated List lst.set(2, 77); // see change in array System.out.println(Arrays.toString(arr)); } } /* Sample output: [10, 5, 3, 6, 7, 18] [10, 5, 77, 6, 7, 18] */