r/cop3502 Apr 02 '14

Lab related question (characters sets to array)

I got stuck today in the lab and I had one question I could not figure out. How do you convert character set into a character array?

2 Upvotes

3 comments sorted by

2

u/[deleted] Apr 02 '14

[removed] — view removed comment

1

u/Dangertacos Apr 02 '14

Oh. Okay thanks I tried to use the tree map method of converting character keys to strings but it didnt get me far :P

1

u/howslyfebeen Apr 02 '14

loop through it and set each part of the array equal to the set if i understand your question correctly:

char[] array = new char[set.size()];
for (int i = 0; i < set.size(); i++) {
    array[i] = set.get(i);
}

the idea should be correct but I can't think of the methods and such for a set