I am making a program where I declared a Stack and named it "words". I used this code, like so:
Stack <String> words = new Stack<String>();
but when I tried to use this code to shuffle the words in it, an error about it being a stack appears:
Collections.shuffle(words);
int mistakes = 0;
final String CORRECT_WORD= words[0];
how can i resolve this error?
If you need the first value from words, just use pop():
final String CORRECT_WORD = words.pop();
or Vector's elementAt(0).
final String CORRECT_WORD = words.elementAt(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With