I'm new to Java most basic question about arrays!
- by ambidextorous
Hey I have not been able to find a proper answer on any forums about this but how exactly do I pass an array to a class?
public class TestArray {
String name;
String[] array;
public TestArray(String name, String[] anArray){
this.name = name;
int len = anArray.length;
this.array = new String[len];
for (int i = 0; i < len; i++){
this.array[i] = new String(anArray[i]);
}
}
}
public static void main(String[] args){
String[] anArray = new String[2];
anArray[0] = new String("Test");
anArray[1] = new String("Test2");
TestArray work = new TestArray("Jordan", anArray?);
}
}