I'm new to Java most basic question about arrays!

Posted by ambidextorous on Stack Overflow See other posts from Stack Overflow or by ambidextorous
Published on 2010-06-01T15:51:04Z Indexed on 2010/06/01 15:53 UTC
Read the original article Hit count: 206

Filed under:
|
|

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?);

} }

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse