View Single Post
  #1 (permalink)  
Old 07-01-2009, 09:10 PM
fullmetaljacket fullmetaljacket is offline
Member
 
Join Date: Mar 2009
Posts: 61
Rep Power: 0
fullmetaljacket is on a distinguished road
Default Creating a constructor with arrays and arguments
Dear All,

I'm having some problems again! I am trying to create a constructor with the following array requirements.

Firstly - I have created a private instance variable called test that is suitable for holding an array of characters.

private char[] test;

I am then asked to create a constructor that takes a single argument of type String. The constructor should create an array of char which is the same size as the constructors argument and assign it to test. Then the code should copy all the letters from the argument into the array referenced by test in the same order.

I have:

Code:
public myString(String[] args)
{
   this.test = args;
}
I get the error wrong type. This I understand. I need to cast the String argument to type char. But I only have examples of using CharAt(index), which will return only one character not all as Char.

Can anyone let me know where and what I have done wrong.

All help gratefully accepted.

All the best - FMJ.
Reply With Quote