package com.mindprod.example;
import java.util.Arrays;
import java.util.List;
/**
* Demonstrate Arrays.asList( int[] ) gotcha.
* <p/>
* See the goofy thing happening with Arrays.asList( int[] ).
* <p/>
* int[] becomes the one and only element of a List of <int[]> objects!! Arrays.asList is advertised to support the
* original array as a backing array so that when you change the List (actually an ArrayList) produced by asList, the
* original array is also supposed to change.
* <p/>
* However, if you attempt to do Arrays.asList( int[] ), this won't work. There is no invisible backing int[] or
* Integer[] created either. All I can say is don't feed an int[] to asList. Use Arrays.asList(Integer[]) boxed
* manually.
* <p/>
* composed with IntelliJ IDEA
*
* @author Roedy Green, Canadian Mind Products
* @version 1.1, 2007-10-04
*/
public class TestArraysAsList
{
/**
* number of cards in a deck
*/
private static final int DECKSIZE = 52;
/**
* main method.
*
* @param args the command line argument, not used
*/
@SuppressWarnings( { "PrimitiveArrayArgumentToVariableArgMethod" } )
public static void main( String[] args )
{
int deck[] = new int[DECKSIZE];
for ( int i = 0; i < DECKSIZE; i++ )
{
deck[ i ] = i;
}
List list = Arrays.asList( deck );
System.out.println( list.getClass() );
System.out.println( list.size() );
Object elem = list.get( 0 );
System.out.println( elem.getClass() );
}
}