2009/05/27

initial array in java

1. static one:

int[] a;           // Declare a to be an array of ints
a = new int[100];  // Allocate an array of 100 ints
//or in a line
int [] a = new int[100];
//string type
String [] b = new String[100];

2. dynamic one:

Note: ‘Java does not offer arrays that can be extended at run time, for primitives or Objects, so it is common to use a Vector for a set of elements that needs to be able to grow.’ from javalobby

Vector v = new Vector();
int count = v.size();
String[] dynArray = new String[count];
v.copyInto(dynArray);

No comments:

Post a Comment