I'm creating a class with a char[]
array as the only instance variable. I have to use a constructor and accesor methods and such but the difficult part is creating an efficient toString()
method.
Right now, I've initialized the array as:
private char[] tune = new char[5];
My toString() method looks like this:
public String toString() {
return notes[0] + " " + notes[1] + " " + notes[2] + " " + notes[3] + " " + notes[4];
}
My question is: Is there a more efficient method of printing this. I thought of using a for loop, as shown below:
for(int i = 0; i <= tune.length; i++) {
return tune[i] + " ";
}
but I assume that would return tune[0] and just stop.