import java.util.Arrays;
import java.util.List;
/**
*
* Arrays asList
* , .
*
* (1) ,
* (2) asList() , .
* , 。
* : ,
* (3) asList add remove
*
* : Arrays ,asList List Array
* , add remove . , ,
* , asList List
*/
public class AsListTest {
public static void main(String[] args) {
/* : asList */
/* : JDK1.6 List, */
int[] a_int = { 1, 2, 3, 4 };
/* 1,2,3,4, , a_int */
List a_int_List = Arrays.asList(a_int);
foreach(a_int_List);
/* */
foreachForBase(a_int_List);
/* : asList, */
Integer[] a_Integer = new Integer[] { 1, 2, 3, 4 };
List a_Integer_List = Arrays.asList(a_Integer);
foreach(a_Integer_List);
/* : asList List, */
a_Integer_List.set(0, 0);
foreach(a_Integer_List);
foreach(a_Integer);
a_Integer[0] = 5;
foreach(a_Integer_List);
foreach(a_Integer);
/* : , asList List ,
* List ,
*/
/*
* a_int_List.set(0, 0);
* foreach(a_int_List); foreach(a_int);
*/
a_int[0] = 5;
foreachForBase(a_int_List);
foreach(a_int);
}
/* */
private static void foreach(List list) {
for (Object object : list) {
System.out.print(object + " ");
}
System.out.println();
}
private static void foreachForBase(List a_int_List) {
int[] _a_int = (int[]) a_int_List.get(0);
foreach(_a_int);
}
private static void foreach(int[] a_int) {
for (int i : a_int) {
System.out.print(i + " ");
}
System.out.println();
}
private static void foreach(Integer[] _a_Integer) {
for (int i : _a_Integer) {
System.out.print(i + " ");
}
System.out.println();
}
}