Array<Character> letters = new ArrayList<Character>();
char[] characters = new char[row * col];
...
public void createShuffleLetters()
{
//create letters
for(char ch = 'a'; ch <='z'; ch++)
{
letters.add(ch);
}
//shuffle
Collections.shuffle(letters);
//convert arrayList to array
letters.toArray(characters);
}
The line in red seems as if it should work, but I get the following error: The method toArray(T[]) in the type ArrayList<Character> is not applicable for the arguments (char[])
I am trying to take an arraylist of characters and shuffle them then convert that arraylist to an array of chars. Any suggestions will be great.
To elaborate on what llemes said (and he is correct), you are trying to use the following method "public Object[] toArray(Object[] a)" which takes an array of Objects, but you are passing in an array of chars. "char" is a primitive type, not an Object, which is why you are getting the error. On the other hand, the Character class (like every other class), "is-an" Object, so you can use that. Or you could simply use:
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.